PL/SQL式でSQL文を直接使用することはできません:
SQL> begin
2 if (select count(*) from dual) >= 1 then
3 null;
4 end if;
5 end;
6 /
if (select count(*) from dual) >= 1 then
*
ERROR at line 2:
ORA-06550: line 2, column 6:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
...
...
代わりに変数を使用する必要があります。
SQL> set serveroutput on
SQL>
SQL> declare
2 v_count number;
3 begin
4 select count(*) into v_count from dual;
5
6 if v_count >= 1 then
7 dbms_output.put_line('Pass');
8 end if;
9 end;
10 /
Pass
PL/SQL procedure successfully completed.
もちろん、すべてを SQL で実行できる場合もあります。
update my_table
set x = y
where (select count(*) from other_table) >= 1;
何かが不可能であることを証明することは困難です。上記の単純なテスト ケースの他に、ステートメントの構文図を確認できます。どのブランチにもステートメントはIF
ありません。SELECT