This discussion is archived
2 Replies Latest reply: Nov 9, 2012 7:19 AM by 742139 RSS

SQLPLUS - then /else run script.sql

973096 Newbie
Currently Being Moderated
I am having trouble with the script below, would anyone have any suggestions or be able to help me out?

I am trying to do a case statement where I select to see if an ID exists or not and if it doesnt i want to run a .sql file but its not working properly.

select case when exists (select ID from VERSION where ID = '16.1')
then 'ID Exists'
else @script.sql
end
from dual;


Its not allowing me to run the @script.sql with the else statement...does anyone have any suggestions?

Thanks.
  • 1. Re: SQLPLUS - then /else run script.sql
    Frank Kulash Guru
    Currently Being Moderated
    Hi,

    Welcome to the forum!

    Post your question in only one forum; that way, you'll only have to look for answers in one place. Since there are already answers for your question in the SQL forum {message:id=10680342} , you should mark this thread as "Answered" right away, and continue in that other thread.
  • 2. Re: SQLPLUS - then /else run script.sql
    742139 Newbie
    Currently Being Moderated
    create script prompt.sql :
    PROMPT &1

    in your main script:

    define column script_name new_value script_name noprint

    select case when exists(seelct ID from VERSIOn where id = '16.1')
    then 'prompt.sql "ID Exists"'
    else 'script.sql'
    end as script_name
    from dual;

    @&script_name

    Best regards

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points