title: PL/SQL - Execute immediate loop using parameter and if/then statement
body: <p>Within a shell script I am using a pl/sql block to drop certain users using $USER parameter. If another parameter <code>${DROP_AB}</code> is Y then drop all users from the cursor. How do I drop all users except one specific user <code>${USER}AB</code> if the parameter passed is N? Please see below and help with suggestions:</p>
  
  <pre><code>BEGIN
  DECLARE
    CURSOR c1 IS
      SELECT username FROM dba_users WHERE username LIKE '${USER}%';
  BEGIN
    FOR user_rec IN c1
      IF ${DROP_AB}='Y' THEN
        LOOP
          EXECUTE IMMEDIATE 'DROP USER ' ||user_rec.username|| ' CASCADE';
      ELSIF ${DROP_AB}='N' THEN
        LOOP
          --DROP ALL USERS EXCEPT FOR USER '${USER}AB'
     END LOOP;
  END;
  END;
  /
  </code></pre>