Using ACCEPT within a BEGIN block in pl/sql

后端 未结 1 1132
温柔的废话
温柔的废话 2021-01-24 14:06

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:

1条回答
  •  北荒
    北荒 (楼主)
    2021-01-24 14:33

    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.

    0 讨论(0)
提交回复
热议问题