参考: http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_9014.htm#SQLRF55094 官方文档说明, multitable INSERT 不能用在视图上,故D是错误的。
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.实验验证:
[email protected]> 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.
[email protected]> 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.
[email protected]> 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.
[email protected]> 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
[email protected]> 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值。
[email protected]> 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答案:正确,可以删除
[email protected]> delete from sales_staff_vu where EMPLOYEE_ID=145;
1 row deleted.
[email protected]> 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
[email protected]> 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_开头的。
[email protected]> update sales_staff_vu set JOB_ID=‘SA_REP‘ where EMPLOYEE_ID=146;
1 row updated.
[email protected]> 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不能插入非空
[email protected]> 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可以插入视图?
[email protected]> 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.
[email protected]> 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.
[email protected]> 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.
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net