溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

oracle常規(guī)操作

發(fā)布時(shí)間:2020-08-03 04:42:12 來(lái)源:網(wǎng)絡(luò) 閱讀:436 作者:jingnings0 欄目:數(shù)據(jù)庫(kù)
1、創(chuàng)建表

Sql代碼  oracle常規(guī)操作

  1. create table test(  

  2.   id varchar2(10),  

  3.   age number  

  4. );  


2、備份表

Sql代碼  oracle常規(guī)操作

  1. create table   

  2. as   

  3. select * from test group by id;  

 3、刪除表

Sql代碼  oracle常規(guī)操作

  1. drop table test;--刪除表結(jié)構(gòu)和表數(shù)據(jù)  


4、清空表

Sql代碼  oracle常規(guī)操作

  1. truncate table test;--清空數(shù)據(jù)表數(shù)據(jù),沒(méi)有返回余地  

  2. delete from test;---清空數(shù)據(jù)表數(shù)據(jù),有返回余地  

 

5、添加字段下載

Sql代碼  oracle常規(guī)操作

  1. alter table test add (  

  2.   name varchar2(10),  

  3.   interest varchar2(20)  

  4. );  


6、刪除字段

Sql代碼  oracle常規(guī)操作

  1. alter table test drop name;  


7、更新數(shù)據(jù)

7.1更新一條數(shù)據(jù)

Sql代碼  oracle常規(guī)操作

  1. update test t   

  2. set t.id='001'   

  3. where t.id is not null;  

  4. commit;  

 

7.2從其他表更新多條數(shù)據(jù)

Sql代碼 下載 oracle常規(guī)操作

  1. update test t set t.name=(  

  2.   select tm.name   

  3.     from test_common tm   

  4.   where t.id=tm.id  

  5. );  

  6. commit;  

  7. --備注:update數(shù)據(jù)時(shí),最好將update子查詢中的sql單獨(dú)建表,提高更新速度。  

 

7.3在PL/SQL中查詢完數(shù)據(jù)直接進(jìn)入編輯模式更改數(shù)據(jù)

Sql代碼  oracle常規(guī)操作

  1. select * from test for update;  

  2. --備注:更新操作執(zhí)行完,要鎖上數(shù)據(jù)表,同時(shí)執(zhí)行commit提交操作  

 

8、查詢數(shù)據(jù)

Sql代碼  oracle常規(guī)操作

  1. select * from test;  

 9、查詢數(shù)據(jù)表數(shù)量

Sql代碼  下載

  1. select count(0) from test;  

  2. --備注:count(0)或者其他數(shù)字比count(*)更加節(jié)省數(shù)據(jù)庫(kù)資源,高效快捷  


10、插入數(shù)據(jù)

10.1插入一條數(shù)據(jù)中的多個(gè)字段

Sql代碼  oracle常規(guī)操作

  1. insert into test (C1,C2) values(1,'技術(shù)部');  

Sql代碼  oracle常規(guī)操作

  1. insert into test(C1,C2) select C1,C2 from test_common;  

  2. commit;  

 

10.2插入多條數(shù)據(jù)

Sql代碼  oracle常規(guī)操作

  1. insert into test(  

  2.   id,  

  3.   name,  

  4.   age  

  5. )  

  6. select  

  7.   id,  

  8.   name,  

  9.   age  

  10. from test_common;  

  11. commit;  

  12. --備注: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ī)制。  


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI