Quite often it is necessary to do some repetetive operations / few line queries against set of objects. Let's say you have a list of accounts to unlock via
alter user %username% account unlock
and instead of typing the same line multiple times for each user I believe some cycle construction can be used but don't know how to write it in PL/SQL. Can somebody advice on this?
Best Answer
You can generate this sort of statements using dynamic SQL, e.g.
Following up on your latest comment, if you want to manually enumerate the usernames you can use a PL/SQL collection such as a nested table, e.g.
To actually run the commands instead of just printing them, substitute
dbms_output.put_line
withexecute immediate
.