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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.