为什么本规范给出了错误

时间:2014-12-10 12:21:08

标签: database oracle plsql toad

我无法使用简单的SELECT语句初始化变量。

DECLARE
A VARCHAR2(10);
BEGIN
A := (SELECT FIRST_NAME FROM FIMS_OWNER.EMPLOYEE_T WHERE WWID = 'NA734');
END;
/

ERROR:

[Error] Execution (4: 11): ORA-06550: line 4, column 11:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:

   ( - + case mod new not null <an identifier>
   <a double-quoted delimited-identifier> <a bind variable>
   continue avg count current exists max min prior sql stddev
   sum variance execute forall merge time timestamp interval
   date <a string literal with character set specification>
   <a number> <a single-quoted SQL string> pipe
   <an alternatively-quoted string literal with character set specification>
   <an alternat
ORA-06550: line 4, column 76:
PLS-00103: Encountered the symbol ")" when expecting one of the following:

   * & - + ; / at for mod remainder rem <an exponent (**)> and
   or group having intersect minus order start union where
   connect || multiset

如果不可能,那么同样的选择是什么。

PS :我正在使用这样的查询来设置变量(后来使用它)和我的光标,动态地取WWID然后相应地更改值。

图片http://i.stack.imgur.com/wzSDk.png

2 个答案:

答案 0 :(得分:2)

因为在Oracle中,您无法为变量分配查询。但是,您可以查询变量,如...

DECLARE
    A VARCHAR2(10);
BEGIN
    SELECT FIRST_NAME
    INTO A
    FROM FIMS_OWNER.EMPLOYEE_T
    WHERE WWID = 'NA734';
END;
/

答案 1 :(得分:1)

你的代码应该是

DECLARE
A VARCHAR2(10);
BEGIN
SELECT FIRST_NAME INTO A FROM FIMS_OWNER.EMPLOYEE_T WHERE WWID = 'NA734';
END;

您应该使用INTO子句为变量

选择一个值