我使用了相同的代码,但不是运行选项 1 和 2 中的脚本,而是脚本要求这个
这是我使用的链接:How to make a menu in SQLPlus or PL/SQL?
PROMPT 1: Make a sales invoice
PROMPT 2: Inquire a sales invoice
accept selection PROMPT "Enter option 1-2: "
set term off
column script new_value v_script --Q1. What's column script?
select case '&selection.' --from accept above
when '1' then '@test1.sql' --script to run when chosen option 1.
when '2' then '@test2.sql' --script to run when chosen option 2.
else '@FinalAssignment.sql' --this script
end as script --Q2. What script is this referring to?
from dual; --Q3. Don't know this
set term on
@&v_script. --Q4. What script is being ran here?
这是我得到的输出
SQL> @myScript
1: Make a sales invoice
2: Inquire a sales invoice
Enter option 1-2: 1
Enter value for v_script: 1
SP2-0310: unable to open file "1.sql"
我的脚本文件的名称是“myScript”,所以我认为如果输入了无效选项,菜单应该自行重新加载。但是由于某种原因它没有这样做..
我不明白这一点,而且即使执行一个脚本,我也希望代码循环运行,它应该返回菜单并要求另一个选择。如果再次输入无效选项,它应该返回菜单供用户选择另一个选项。
我的包含循环的代码在这里:
PROMPT 1: Make a sales invoice
PROMPT 2: Inquire a sales invoice
accept selection PROMPT "Enter option 1-2: "
set term off
LOOP
column script new_value v_script --Q1. What's column script?
select case '&selection' --from accept above
when '1' then @test1.sql --script to run when chosen option 1.
when '2' then @test2.sql --script to run when chosen option 2.
when '3' then @test3.sql
EXIT WHEN &selection = 4;
else '@myScript.sql' --this script
end as script --Q2. What script is this referring to?
from dual; --Q3. Don't know this
END LOOP;
set term on
@&v_script. --Q4. What script is being ran here?