Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: If EXISTS before insert clause
OK, say I had the following in a .sql file
IF EXISTS(SELECT PRD_UID FROM WST_PRD WHERE PRD_UID = 502)
BEGIN
INSERT INTO WPS_DELB (TABLE_TYPE,FLD_NAME,FKEY_TABLE,FKEY_FLD_NAME)
VALUES ('CFLD','CAGR_UID','CAGR','CAGR_UID') ;
INSERT INTO WPS_DELB (TABLE_TYPE,FLD_NAME,FKEY_TABLE,FKEY_FLD_NAME)
VALUES ('CFLD','LKUP_UID','LKUP','LKUP_UID') ;
INSERT INTO WPS_DELB (TABLE_TYPE,FLD_NAME,FKEY_TABLE,FKEY_FLD_NAME)
VALUES ('CIMP','IMPT_UID','IMPT','IMPT_UID') ;
INSERT INTO WPS_DELB (TABLE_TYPE,FLD_NAME,FKEY_TABLE,FKEY_FLD_NAME)
VALUES ('ITTH','TOLR_UID','TOLR','TOLR_UID') ;
INSERT INTO WPS_DELB (TABLE_TYPE,FLD_NAME,FKEY_TABLE,FKEY_FLD_NAME)
VALUES ('RISK','CATG_UID','CATG','CATG_UID') ;
INSERT INTO WPS_DELB (TABLE_TYPE,FLD_NAME,FKEY_TABLE,FKEY_FLD_NAME)
VALUES ('SCOR','IMPT_UID','IMPT','IMPT_UID') ;
INSERT INTO WPS_DELB (TABLE_TYPE,FLD_NAME,FKEY_TABLE,FKEY_FLD_NAME)
VALUES ('SCOR','PROB_UID','PROB','PROB_UID') ;
INSERT INTO WPS_DELB (TABLE_TYPE,FLD_NAME,FKEY_TABLE,FKEY_FLD_NAME)
VALUES ('SCOR','SEV_UID','SEV','SEV_UID') ;
END
How would I covert that to PL/SQL and run it? It sounds to me like you
are just saying change the top part to:
Declare a NUMBER;
SELECT COUNT(PRD_UID) into a FROM WST_PRD WHERE PRD_UID = 502;
IF (a > 0)
BEGIN
.
.
.
END IF
But if I do that and try to run in TOAD it doesn't work.
I am new to Oracle so any help would be appreciated. I just don't define Oracle as easy. I have worked two places and everyone I have met hates dealing with it. Received on Fri Feb 04 2005 - 16:55:36 CST