I have created a procedure such as the following
CREATE OR REPLACE PROCEDURE drop_if_exists (table_name IN varchar2)
IS
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE table_name';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -942 THEN
RAISE;
END IF;
END;
When I run it as drop_if_exists ( ‘my_table’ ) it says everything was executed successfully, but any table called my_table will still exist after the call to the procedure. Changing to uppercase makes no difference. I guess that the variable simply is not substituted … Any ideas on how to fix it?
You are dropping a table named “table_name”, what is different to deleting the table you pass in the parameter.
Try this:
Anyway, I would NOT advice doing that. Your code is potentially dangerous.