通常情况下,一条SQL语句经过parse,bind variables,execution和fetch,但对于DDL是不经过后面两个阶段的,这个现象是同事刚刚发现,查一下文档上面也确实提到了DDL经过parse就执行了:
PARSE Procedure
This procedure parses the given statement in the given cursor. All statements are parsed immediately. In addition, DDL statements are run immediately when parsed.
There are two versions of the PARSE procedure: one uses a VARCHAR2 statement as an argument, and the other uses a VARCHAR2S (table of VARCHAR2) as an argument.
下面是一个测试例子:
SQL> declare
2 cr integer;
3 begin
4 cr:=dbms_sql.open_cursor;
5 dbms_sql.parse(cr,'create table abc as select * from dba_objects',dbms_sql.native);
6 dbms_sql.close_cursor(cr);
7 end;
8 /
PL/SQL procedure successfully completed.
SQL> select count(1) from abc;
COUNT(1)
----------
29202
SQL> declare
2 cr integer;
3 begin
4 cr:=dbms_sql.open_cursor;
5 dbms_sql.parse(cr,'truncate table abc',dbms_sql.native);
6 dbms_sql.close_cursor(cr);
7 end;
8 /
PL/SQL procedure successfully completed.
SQL> select count(1) from abc;
COUNT(1)
----------
0
对于truncate如果不小心执行了parse,整个表的数据就丢失了!
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/45188/viewspace-1030983/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/45188/viewspace-1030983/
本文通过测试案例展示了在Oracle数据库中,数据定义语言(DDL)语句在解析(PARSE)阶段即被执行的特点。这与数据操作语言(DML)语句不同,后者还需要经历bindvariables、execution和fetch等步骤。这一特性意味着DDL语句如创建表或截断表的操作,在仅仅进行解析时就会生效。
2万+

被折叠的 条评论
为什么被折叠?



