Oracle 學習使用SQL語四 DML語句

2021-08-29 21:57:26 字數 1980 閱讀 5149

[b]一、insert插入資料[/b]

[b]1、將整張表的資料插入到一張表中[/b]

[color=red] 語法:insert into 表名(子查詢)[/color]

使用子查詢將整張表插入到制定的表中,有兩種方式,如下:

(1)、insert into cip_test (select *from cip_tmp)。

",有點不明白,待研究。我按照第二種方法插入50000條資料,結果toad死掉了,不知道為什麼。[/color]

[b]2、將整張表的輸入插入到多個表中[/b]

[b](1)、使用all操作符執行插入操作[/b]

使用insert語句可以將某張表的資料同時插入到多張表中,語法如下:

[color=red] insert all insert_into_clause[value_clause] 子查詢;

如上所示:insert_into_clause指insert子句,value_clause指定值子句[/color]

insert all into cip_test into cip_temp select * from cip_tmp where id<10;

[color=blue]插入的資料中cip_test表中的資料為1—10,cip_temp表中的資料為1—10,cip_temps表中的資料為1—10。[/color]

insert  all 

when id between 1 and 10 then into cip_test

when id between 11 and 20 then into cip_temp

when id between 21 and 30 then into cip_temps

select * from cip_tmp where id<30;

[color=blue]插入的資料中cip_test表中的資料為1—10,cip_temp表中的資料為11—20,cip_temps表中的資料為21—30。[/color]

[color=red]注意:sql語法1是將查詢的資訊全部插入的指定的表中。sql2語句2是將查詢的結果按照條件插入到指定的表中。[/color]

[b](2)、使用first操作符執行插入操作[/b]

當使用first操作符插入多表資料時,當先前條件已經滿足,並且已經插入到表中,則該資料在後續插入中將不會在被用到。**例如:

insert  first

when id <=10 then into cip_test

when id <=20 then into cip_temp

when id <=30 then into cip_temps

select * from cip_tmp where id<30;

[color=blue]插入的資料中cip_test表中的資料為1—10,cip_temp表中的資料為11—20,cip_temps表中的資料為21—30。[/color]

[b]二、update更新資料[/b]

當使用update語句更新資料時,不僅可以使用表示式、數值直接更新資料,可可以使用子查詢更新資料,某些情況下使用子查詢更新效率更好,例如:

update cip_temp set (name,age,address)=(select name,age,address from cip_test where id=1) where id=20;[/code

[b]三、delete刪除資料[/b]

當使用delete語句刪除資料時,可以在where子句中指定值,並根據條件刪除資料,另外也可以再where子句中使用子查詢做為條件刪除資料,例如:

[code="oracle"]delete from cip_temp where name=(select name from cip_test where id=1)

Oracle與Oracle的SQL操作語句

oracle 也是一種資料庫管理系統 儲存結構分類 邏輯儲存結構,物理儲存結構 邏輯儲存結構 資料塊 資料塊是oracle邏輯儲存結構的最小邏輯結構,乙個資料塊對應乙個或多個物理塊,資料塊的結構包括塊頭和儲存區的兩個部分 塊頭包括 資料塊標題,表目錄,行目錄 儲存區 自由空間,行資料 資料區 資料區...

oracle使用sql語句 基本的增 刪 改語句

oracle使用sql語句增加修改刪除字段示例 新增欄位的語法 alter table tablename add column datatype default value null not null 修改欄位的語法 alter table tablename modify column data...

Java喬曉松 oracle的基本sql語句

select from table select 標識 選擇哪些列。from 標識從哪個表中選擇。select from departments select department id,location id from departments sql 語言大小寫不敏感。sql 可以寫在一行或者多行...