oracle之多表插入語句

2021-10-05 02:23:17 字數 1867 閱讀 5135

1、無條件insert

首先建一張表

再建立如下兩張表

create table emp1

(id   varchar2(4),

name varchar2(50),

sal  number(7,2)

)create table emp2

(id    varchar2(4),

name  varchar2(50),

money number(7,2)

)無條件插入:

2、有條件insert

insert all

when id in ('1','2') then  --滿足此條件插入emp1

into emp1(id,name,sal) values (id,name,sal)

when id in ('3') then --滿足此條件插入emp2

into emp2(id,name,money) values (id,name,money)

select * from emp;

insert all

when id in ('1','2') then  --滿足此條件插入emp1

into emp1(id,name,sal) values (id,name,sal)

--這裡不加條件的話此處條件同 emp1插入條件

into emp2(id,name,money) values (id,name,money)

select * from emp;

insert all

--這裡無插入條件而emp2有插入條件,會報錯

into emp1(id,name,sal) values (id,name,sal)

when id in ('3') then --滿足此條件插入emp2

into emp2(id,name,money) values (id,name,money)

select * from emp;

3、有條件insert first

第乙個表符合條件後,第二張表不會插入對應的行;如下,第二張表僅會插入id='3'的資料

insert first

when id in ('1','2') then

into emp1(id,name,sal) values (id,name,sal)

when id in ('1','2','3') then

into emp2(id,name,money) values (id,name,money)

select * from emp

多表插入語句

多表插入語句分為以下四種 無條件insert。有條件insert all。轉置insert。有條件insert first。首先建立測試用表 create table emp empno number 4 ename varchar2 10 job varchar2 9 deptno number ...

Oracle insert多表插入語句

oracle 多表插入 如下 create table emp1 as select empno,ename,job from emp where 1 2 create table emp2 as select empno,ename,deptno from emp where 1 2 沒有條件in...

Oracle批量插入語句

insert all into test 12 id,name values id,name select id,name from process steps where name in pack功能測試 72hours pack功能測試 144hours pack功能測試 216hours pa...