is it ok to do a Drop inside a PL SQL.
whats wrong with this SQL
I am trying to drop all users.
The problem is in the drop user username cascase statement
connect sys/abcsds@1.1.1.1 as sysdba
exec dbms_output.enable(1000000);
set serveroutput on
DECLARE
BEGIN
for rec in (select username from dba_users where username LIKE 'S%' AND username NOT LIKE 'SY%') loop
dbms_output.put_line(to_char(rec.username));
dbms_sql.execute('drop user rec.username cascade');
end loop;
END;
.
run;
exit;
You can use DDL in a loop but you’ll have to build the string since you can’t bind object names.
For example:
Be careful though, DDL is not transactional in Oracle (it performs a commit before and after) and thus you won’t be able to rollback any changes.