Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop users by mask in the Oracle RDBMS

I want to drop all users who have 'WIN' at the start of their name (for example, 'WIN$DOWS'). Is it possible to write something like like the follownig?

drop user where name like 'WIN%'
like image 790
Petro Semeniuk Avatar asked Nov 03 '25 19:11

Petro Semeniuk


1 Answers

The DROP USER statement doesn't support a WHERE clause, much less LIKE and wildcarding.

You need to fetch a list of users from DBA_USERS that match, and iterate over that list:

--Bye Users!
FOR i IN (SELECT t.username
            FROM DBA_USERS t
           WHERE t.username LIKE 'WIN%') LOOP
  EXECUTE IMMEDIATE 'drop user '|| i.username ||'';
END LOOP;
like image 190
OMG Ponies Avatar answered Nov 07 '25 09:11

OMG Ponies



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!