I am taking a database class and at the beginning of the lab section of the class we usually have to drop all the tables in the database created previously. I wanted to be able to run a script that does this dynamically, but cannot seem to get it to work. Here is the code I have so far.
declare tname string(50);
cursor ctable is select table_name from user_tables;
begin
open ctable;
LOOP
FETCH ctable into tname;
if tname != '' then
execute immediate 'drop table ' || tname;
END if;
EXIT WHEN ctable%NOTFOUND;
END LOOP;
close ctable;
end;
If someone could point me in the right direction as to what I am doing wrong that would great. Thanks.