ITPub博客

首页 > 数据库 > Oracle > DDL语句parse阶段隐式执行代码

DDL语句parse阶段隐式执行代码

原创 Oracle 作者:pingshx 时间:2010-01-29 13:45:22 0 删除 编辑

通常情况下,一条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,整个表的数据就丢失了!

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/45188/viewspace-1030983/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 又一则ORA-4030
请登录后发表评论 登录
全部评论
  • 博文量
    44
  • 访问量
    156408