I am trying to use ACCEPT in my BEGIN block but I keep getting errors. I want to accept user input if the if condition is fired. How can I fix this? Below is my script:
ACCEPT
is a SQL*Plus command. It is interpreted by the client (SQL*Plus) before code is sent to the database. PL/SQL is a language that runs exclusively on the server. You cannot, therefore, intertwine the two. You cannot embed SQL*Plus commands inside a PL/SQL block. As a general rule, PL/SQL blocks cannot interact with users.
If you want to get really, really down in the weeds, it would possible to build a rather complicated bit of branching logic into your SQL*Plus script so that a second script with only the three ACCEPT
statements would be run if and only if &CashAmount < (CashTotal - 0)
but that is rarely an appropriate approach. That would probably involve creating a new SQL*Plus variable called, say, next_script
, populating that variable as part of your block, and then dynamically calling next_script
in your script. That is not a way, however, to build solid, reliable, easy to maintain systems.