SP2-0552:绑定变量" VAR1"没有宣布

时间:2016-12-01 00:52:26

标签: sql oracle10g

set pagesize 0 echo off;
SET LINESIZE 30000 LONG 300000000 LONGCHUNKSIZE 30000 Trimspool on;

WHENEVER SQLERROR EXIT SQL.SQLCODE

var1 timestamp
exec :var1 := select LOAD_TIME from xml_audit where subject_area=&2 and load_time=(select max(load_time) from xml_audit where status='PASSED');

我在下面的查询中使用varibale但是得到错误

SP2-0552: Bind variable "VAR1" not declared.

请帮助我

2 个答案:

答案 0 :(得分:0)

在PL / SQL中,您必须选择一个变量。

  

SELECT col INTO变量FROM table;

您还需要声明一个匿名块:

DECLARE
d_date DATE;
BEGIN
    SELECT sysdate INTO d_date FROM dual;
    SELECT col FROM table WHERE some_date = d_date
END;

答案 1 :(得分:0)

遵循以下语法 - 这适用于SQL PLus,并且应该在Toad等中使用......:

VARIABLE x VARCHAR2(300);
EXEC :x:= 'MILLER';
SELECT ename FROM scott.emp WHERE ename = :x
/

SQL> VARIABLE x VARCHAR2(300);
SQL> EXEC :x:= 'MILLER';

PL/SQL procedure successfully completed.

SQL> SELECT ename FROM scott.emp WHERE ename = :x;

ENAME
----------
MILLER