如何在oracle pl / sql语句中声明查询?

时间:2016-01-19 21:28:18

标签: oracle plsql oracle-sqldeveloper

我对Oracle很新,但我的任务就是编写这个声明。

BEGIN
FOR partition IN 1..32 LOOP
    lQuery := 'UPDATE CORE.tbl PARTITION(tbl' || LPAD(partition, 2, '0') || ') SET p = NULL '
           || 'WHERE p IS NOT NULL';

    EXECUTE IMMEDIATE lQuery;
END LOOP;
END;

但是,我收到以下错误

Error starting at line 1 in command:
BEGIN
FOR partition IN 1..32 LOOP
    lQuery := 'UPDATE CORE.user_login PARTITION(user_login' || LPAD(partition, 2, '0') || ') SET password_md5 = NULL '
           || 'WHERE password_md5 IS NOT NULL';

    EXECUTE IMMEDIATE lQuery;
END LOOP;
END;
Error report:
ORA-06550: line 3, column 5:
PLS-00201: identifier 'LQUERY' must be declared
ORA-06550: line 3, column 5:
PL/SQL: Statement ignored
ORA-06550: line 6, column 23:
PLS-00201: identifier 'LQUERY' must be declared
ORA-06550: line 6, column 5:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

当我尝试运行它时。我理解这可能是因为没有声明lQuery但谷歌搜索在线显示了一些声明某种类型变量的例子,例如(整数,varchar ......等),但它们都没有显示如何将查询声明为本声明预计。

1 个答案:

答案 0 :(得分:1)

您的声明可能只是声明为varchar2。例如:

declare
  vsql varchar2(1000);
  n   integer;
begin
  vsql := 'select 1 from dual';
  execute immediate vsql into n;
  dbms_output.put_line(n);
end;