On the move:

I'm currently moving the following to their own blogs: Unix, HTML for Blogs, Perl & Java.
The links are on the left side.

Monday, October 13, 2008

To Conditionally Call Code in SQL*Plus

Since SQL*Plus has no 'If' options (outside of queries) you need a different way to conditionally call another query. One way to do that is to have a query that checks for the condition you're looking for. If it is found, &Ex_If will be set to the name of the query I wish to run. It is first undefined so we're ready for the next execution.

I use this when there are some statements I need to jump around based on conditions. In SQL*Plus, you'll need to move those statements to another query, and then insert this type of code.

My main code is Ex_If.Sql:
Undefine Ex_If                        
Column Ex_If New_Value Ex_If

Select 'RunThis' As Ex_If
From Emp
Where Empno = &Empno;


If the condition is found, it calls RunThis.Sql
Select 'This Works!' From Dual;

No comments:

Post a Comment