同じコードを使用しましたが、オプション 1 と 2 でスクリプトを実行する代わりに、スクリプトはこれを要求します
これは私が使用したリンクです: SQLPlus または 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」なので、無効なオプションが入力された場合、メニューは自動的にリロードされるはずです。しかし、何らかの理由でそうしていません..
私はこれを取得しません。また、1 つのスクリプトが実行された場合でもコードをループで実行したい場合は、メニューに戻って別の選択を要求する必要があります。無効なオプションが再度入力された場合、ユーザーが別の選択肢を選択できるようにメニューに戻る必要があります。
ループが含まれている私のコードは次のとおりです。
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?