Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: script to dynmically create all foreign key constraints

Re: script to dynmically create all foreign key constraints

From: Billy Verreynne <vslabs_at_onwe.co.za>
Date: Wed, 11 Dec 2002 07:58:54 +0200
Message-ID: <at6kaq$l7e$1@ctb-nnrp2.saix.net>


Steve wrote:

> I know this sounds kind of hokey but the ON DELETE
> CASCADE functionality is only ever required once every odd month so. I
> know I can get the constraints from import export but I'd like a
> dynaminc sql that I can just edit one and run.

See the details on the DBMS_SQL package. It supports an EXEC SQL function similar to that in Pro*C - allowing you to write dynamic SQL inside a stored proc.

E.g. (written from memory and not tested)

PROCEDURE ExecSQL ( sql IN VARCHAR2, ret OUT integer ) IS   cid integer;
BEGIN
  cid := DBMS_SQL.Open_Cursor;

  dbms_sql.Parse( cid, sql, DBMS_SQL.NATIVE );   ret := DBMS_SQL.Execute( cid );

  DBMS_SQL.Close_Cursor( cid );

  EXCEPTION
    WHEN OTHERS THEN

      raise_application_error(-20101, 'Error in ExecSQL : ' ||
                              SQLERRM(SQLCODE));

  commit;
END;  

--
Billy
Received on Tue Dec 10 2002 - 23:58:54 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US