I want to run two queries in script. Oracle. Need help
i have following two queries, one is create procedure query and other is the call to the same procedure.
they both run fine when running indiviually, but when i try to run them together in one go i get errors: like executed with warnings and the results are not proper with that.
can you please tell me how can i achieve this? may be it has to do soem thing with execute immediate , but i am new to this so dont kno开发者_开发问答w how to convert my first query to be executed with execute immediate.
Thanks in advance Ashish
CREATE or replace PROCEDURE DP_DROP_FKEY_PROC (NS IN varchar2,
NM IN varchar2, FK IN varchar2)
IS
S VARCHAR2(150) := '';
I NUMBER;
BEGIN
I := 0;
SELECT COUNT(*) INTO I FROM ALL_CONSTRAINTS C
WHERE (C.OWNER = NS) AND (C.TABLE_NAME = NM) AND (C.CONSTRAINT_NAME = FK) ;
IF (I = 1) THEN
S := 'ALTER TABLE "' || NS || '"."' || NM || '" DROP CONSTRAINT "' || FK || '"';
EXECUTE IMMEDIATE S;
END IF;
END;
CALL DP_DROP_FKEY_PROC('SomeOwnerName', 'TableName', 'ConstraintName');
I tried the procedure and it worked.
Make sure to pass all the parameters uppercase as ALL_CONSTRAINTS
holds them uppercase, so that would beCALL dp_drop_fkey_proc('SOMEOWNERNAME', 'TABLENAME', 'CONSTRAINTNAME');
in your example.
If this does not help, please provide the error you get.
EDIT:
The way you do it, it will always be two steps:
- Create the procedure
- Run it
Once the procedure is compiled, you can run it again and again with different parameters.
If you want to do it with one call, the only way that makes sense is to call
ALTER TABLE "SOMEOWNERNAME"."TABLENAME" DROP CONSTRAINT "CONSTRAINTNAME"
EDIT2:
Maybe I did not understand what you wanted to do. Can you try to add a slash character /
in the line after your END;
?
-- [...]
END;
/
CALL DP_DROP_FKEY_PROC('SomeOwnerName', 'TableName', 'ConstraintName');
精彩评论