Search code examples
oracle-databasepromptsql-scripts

How to create if-then-else statement in an oracle sql script?


I am writing an sql script, whitch should ask a question, and the continuing would depend on the user's input.

I have tried this:

prompt script started
accept partitioning prompt "Do you want to partition the table? (Y/N):"
if ($partitioning=Y)
    prompt ok, it will be partitioned
else
    prompt ok, it won't be partitioned
end;

But I get

ORA-00900 exception, the if statement is not allowed here.

Is there a way to use if-then-else in a single sql script? Please give me an example, if it possible.


Solution

  • In the comments, I got the answer:

    http://www.itbh.at/simulating-control-flow-statements-in-sqlplus/?lang=en