Select 转换成变量并用到 IF (oracle)

Select Into Variable and use it into IF (oracle)

我得到了一个程序,我想将值插入到 Col1 的变量中:

Procedure insertX
IS
 var1 varchar2(100) := '';
 check_s1 : = 'select Col1 into '||var1||' from table1';    
begin
 EXECUTE IMMEDIATE check_s1;

  if var1 is null then
   ...
   else
   ...
  end if;    
end;

但是当我执行它的时候出了点问题。

据我所知 select 有错误。

如何将值插入我的 Var1,然后在 IF 条件下使用它?

语法错误。应该是

SQL> set serveroutput on
SQL> declare
  2    var1 varchar2(100);
  3    check_s1 varchar2(100) := 'select dummy from dual';
  4  begin
  5    execute immediate check_s1 into var1;
  6
  7    if var1 is null then
  8       dbms_output.put_line('var1 is null');
  9    else
 10       dbms_output.put_line('var1 = ' || var1);
 11    end if;
 12  end;
 13  /
var1 = X

PL/SQL procedure successfully completed.

SQL>