Truncating a table in a stored procedure

前端 未结 4 1862
南笙
南笙 2020-12-08 03:57

When I run the following in an Oracle shell it works fine

truncate table table_name

But when I try to put it in a stored procedure

4条回答
  •  臣服心动
    2020-12-08 04:36

    As well as execute immediate you can also use

    DBMS_UTILITY.EXEC_DDL_STATEMENT('TRUNCATE TABLE tablename;');

    The statement fails because the stored proc is executing DDL and some instances of DDL could invalidate the stored proc. By using the execute immediate or exec_ddl approaches the DDL is implemented through unparsed code.

    When doing this you neeed to look out for the fact that DDL issues an implicit commit both before and after execution.

提交回复
热议问题