Quantcast
Channel: SCN : Discussion List - SAP PowerDesigner
Viewing all articles
Browse latest Browse all 739

How to generate DDL wrapped in PL/SQL?

$
0
0

My company is looking to do continuous integration / continuous deployment of database code.  For example, when we generate the DDL for, say, a CREATE TABLE statement, we want to make the code smart enough to issue a DROP only if the table already exists in the database.  That is, want to generate the following for a table DROP:

 

DECLARE

  TABLE_EXISTS NUMBER;

BEGIN

SELECT COUNT(*)

  INTO TABLE_EXISTS

  FROM ALL_TABLES

  WHERE TABLE_NAME = UPPER('MY_TABLE')

  AND ' '||OWNER||'.' = nvl(UPPER(' SCOTT.'),' '||OWNER||'.');

IF TABLE_EXISTS > 0 THEN

  DBMS_OUTPUT.PUT_LINE('-dropping table         SCOTT.MY_TABLE');

  EXECUTE IMMEDIATE 'drop table SCOTT.MY_TABLE cascade constraints';

END IF;

END;

/

 

As a prototype, we have customized the DROP TABLE statement in the Oracle 11g DBMS file in C:\Program Files (x86)\Sybase\PowerDesigner 16\Resource Files\DBMS\ora11g.xdb to generate PL/SQL code as a wrapper to test whether the table already exists.  This works fine. However it means our logic is wired to a specific DBMS file.  Any ideas about alternate ways of wrapping PL/SQL code around DDL statements?


Viewing all articles
Browse latest Browse all 739

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>