Restrictions on Multitable Inserts Multitable inserts are subject to the following restrictions:
-
You can perform multitable inserts only on tables, not on views or materialized views.
-
You cannot perform a multitable insert into a remote table.
-
You cannot specify a
TABLE
collection expression when performing a multitable insert. -
In a multitable insert, all of the
insert_into_clause
s cannot combine to specify more than 999 target columns. -
Multitable inserts are not parallelized if any target table is index organized or if any target table has a bitmap index defined on it.
-
Plan stability is not supported for multitable insert statements.
-
You cannot specify a sequence in any part of a multitable insert statement. A multitable insert is considered a single SQL statement. Therefore, the first reference to
NEXTVAL
generates the next number, and all subsequent references in the statement return the same number.实验验证:
hr@TEST1107> create table emp
2 (employee_id number primary key,
3 last_name varchar2(25) not null,
4 department_id number(2) not null,
5 job_id varchar2(8),
6 salary number(10,2)
7 );
Table created.
hr@TEST1107> create or replace view sales_staff_vu as
2 select employee_id,last_name,job_id
3 from emp
4 where job_id like 'SA_%'
5 with check option
6 /
View created.
hr@TEST1107> insert into emp select EMPLOYEE_ID,LAST_NAME,DEPARTMENT_ID,JOB_ID,SALARY from employees
2 where job_id like 'SA_%' and rownum<6
3 /
5 rows created.
hr@TEST1107> select * from emp;
EMPLOYEE_ID LAST_NAME DEPARTMENT_ID JOB_ID SALARY
----------- ------------------------- ------------- -------- ----------
145 Russell 80 SA_MAN 14000
146 Partners 80 SA_MAN 13500
147 Errazuriz 80 SA_MAN 12000
148 Cambrault 80 SA_MAN 11000
149 Zlotkey 80 SA_MAN 10500
hr@TEST1107> select * from sales_staff_vu;
EMPLOYEE_ID LAST_NAME JOB_ID
----------- ------------------------- --------
145 Russell SA_MAN
146 Partners SA_MAN
147 Errazuriz SA_MAN
148 Cambrault SA_MAN
149 Zlotkey SA_MAN
A答案:A答案错误,DEPARTMENT_ID为非空,不能插入null值。
hr@TEST1107> insert into sales_staff_vu values (501,'lihua','SA_MAN');
insert into sales_staff_vu values (501,'lihua','SA_MAN')
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("HR"."EMP"."DEPARTMENT_ID")
B答案:正确,可以删除
hr@TEST1107> delete from sales_staff_vu where EMPLOYEE_ID=145;
1 row deleted.
hr@TEST1107> select * from sales_staff_vu;
EMPLOYEE_ID LAST_NAME JOB_ID
----------- ------------------------- --------
146 Partners SA_MAN
147 Errazuriz SA_MAN
148 Cambrault SA_MAN
149 Zlotkey SA_MAN
hr@TEST1107> select * from emp;
EMPLOYEE_ID LAST_NAME DEPARTMENT_ID JOB_ID SALARY
----------- ------------------------- ------------- -------- ----------
146 Partners 80 SA_MAN 13500
147 Errazuriz 80 SA_MAN 12000
148 Cambrault 80 SA_MAN 11000
149 Zlotkey 80 SA_MAN 10500
C答案:可以将job_id更新为SA_开头的,不能更新为其他不是SA_开头的。
hr@TEST1107> update sales_staff_vu set JOB_ID='SA_REP' where EMPLOYEE_ID=146;
1 row updated.
hr@TEST1107> update sales_staff_vu set JOB_ID='MK_MAN' where EMPLOYEE_ID=147;
update sales_staff_vu set JOB_ID='MK_MAN' where EMPLOYEE_ID=147
*
ERROR at line 1:
ORA-01402: view WITH CHECK OPTION where-clause violation
D答案:multitable INSERT不能插入非空
hr@TEST1107> insert into sales_staff_vu
2 select EMPLOYEE_ID,LAST_NAME,JOB_ID from employees
3 where job_id like 'SA_%'
4 /
insert into sales_staff_vu
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("HR"."EMP"."DEPARTMENT_ID")
实验证明,multitable INSERT可以插入视图?
hr@TEST1107> create or replace view sales_staff_vu_new as
2 select employee_id,last_name,job_id,department_id from emp
3 where job_id like 'SA_%'
4 with check option
5 /
View created.
hr@TEST1107> insert into sales_staff_vu_new
2 select EMPLOYEE_ID,LAST_NAME,JOB_ID,DEPARTMENT_ID from employees where job_id like 'SA_%'
3 and EMPLOYEE_ID in (150,151);
2 rows created.
hr@TEST1107> select * from sales_staff_vu_new;
EMPLOYEE_ID LAST_NAME JOB_ID DEPARTMENT_ID
----------- ------------------------- -------- -------------
146 Partners SA_REP 80
147 Errazuriz SA_MAN 80
148 Cambrault SA_MAN 80
149 Zlotkey SA_MAN 80
150 Tucker SA_REP 80
151 Bernstein SA_REP 80
6 rows selected.