×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Oracle: All versions FAQ

SQL Scripts

SQL*Plus IF / THEN / EXIT method by nbateman
Posted: 27 Jun 11

The requirement is to be able to exit SQL*Plus depending on a condition tested within the script.

The problem is that the IF/THEN/ELSE construct is for PL*SQL, not SQL*Plus and the SQL*Plus command exit is not allowed. For example, the following does not work:

CODE

begin
   IF :returncode != 0 THEN
      exit :returncode;
   END IF;
end;  

The simplest solution requires two files to be set up in advance:
1. exit.sql containing the single line "exit &1"
2. continue.sql which will be empty


The following can then be used to either continue the script (when 0 returned) or exit (when 0 NOT returned):

CODE

COLUMN returnvalue NEW_VALUE returnvalue
COLUMN action NEW_VALUE action  

SELECT function() AS returnvalue FROM dual;

SELECT decode(&&returnvalue , 0, 'continue', 'exit') AS action FROM dual;

@&&action &&returnvalue

 

Back to Oracle: All versions FAQ Index
Back to Oracle: All versions Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close