Sql代碼
成都創(chuàng)新互聯(lián)公司是專業(yè)的卓尼網(wǎng)站建設(shè)公司,卓尼接單;提供成都做網(wǎng)站、網(wǎng)站設(shè)計(jì),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行卓尼網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
create table test(
id varchar2(10),
age number
);
Sql代碼
create table
as
select * from test group by id;
Sql代碼
drop table test;--刪除表結(jié)構(gòu)和表數(shù)據(jù)
Sql代碼
truncate table test;--清空數(shù)據(jù)表數(shù)據(jù),沒(méi)有返回余地
delete from test;---清空數(shù)據(jù)表數(shù)據(jù),有返回余地
5、添加字段下載
Sql代碼
alter table test add (
name varchar2(10),
interest varchar2(20)
);
Sql代碼
alter table test drop name;
7.1更新一條數(shù)據(jù)
Sql代碼
update test t
set t.id='001'
where t.id is not null;
commit;
7.2從其他表更新多條數(shù)據(jù)
Sql代碼 下載
update test t set t.name=(
select tm.name
from test_common tm
where t.id=tm.id
);
commit;
--備注:update數(shù)據(jù)時(shí),最好將update子查詢中的sql單獨(dú)建表,提高更新速度。
7.3在PL/SQL中查詢完數(shù)據(jù)直接進(jìn)入編輯模式更改數(shù)據(jù)
Sql代碼
select * from test for update;
--備注:更新操作執(zhí)行完,要鎖上數(shù)據(jù)表,同時(shí)執(zhí)行commit提交操作
8、查詢數(shù)據(jù)
Sql代碼
select * from test;
Sql代碼 下載
select count(0) from test;
--備注:count(0)或者其他數(shù)字比count(*)更加節(jié)省數(shù)據(jù)庫(kù)資源,高效快捷
10.1插入一條數(shù)據(jù)中的多個(gè)字段
Sql代碼
insert into test (C1,C2) values(1,'技術(shù)部');
Sql代碼
insert into test(C1,C2) select C1,C2 from test_common;
commit;
10.2插入多條數(shù)據(jù)
Sql代碼
insert into test(
id,
name,
age
)
select
id,
name,
age
from test_common;
commit;
--備注:1、插入多條數(shù)據(jù)時(shí),insert into語(yǔ)句后面沒(méi)有values,直接拼接數(shù)據(jù)查詢語(yǔ)句;2、在oracle中對(duì)數(shù)據(jù)表進(jìn)行了insert、update、delete等操作后,要執(zhí)行commit提交,否則在系統(tǒng)處是禁止操作數(shù)據(jù)庫(kù)的,因?yàn)榇藭r(shí)數(shù)據(jù)庫(kù)已經(jīng)被鎖死,這是數(shù)據(jù)庫(kù)為了防止多人同時(shí)修改數(shù)據(jù)庫(kù)數(shù)據(jù)造成混亂的一種防范機(jī)制。