开发者

drop tablespace if do not exist

I have written pl/sql script (works, but doesn't look nice):

DECLARE
   v_exists NUMBER;
BEGIN
   SELECT count(*) INTO v_exists FROM dba_tablespaces WHERE tablespace_name = 'hr_test';
   IF v_exists > 0 THEN
   BEGIN
      EXECUTE IMMEDIATE 'DROP TABLESPACE hr_test INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS';
   END;
   END IF;
   EXECUTE IMMEDIATE 'CREATE TABLESPACE hr_RJ DATAFILE ''E:\hr_test_01.dbf'' SIZE 16M';
END;

Is there any way to rewrite this script without EXECUTE IMMEDIAT开发者_如何学编程E?


No. You cannot issue DDL statements in static PL/SQL.

And yes, it is perfectly fine to use native dynamic SQL for DDL purposes:

You need dynamic SQL in the following situations:

You want to execute a SQL data definition statement (such as CREATE), a data control statement (such as GRANT), or a session control statement (such as ALTER SESSION). In PL/SQL, such statements cannot be executed statically.

Oracle dynamic SQL

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜