为啥此代码给出错误
Posted
技术标签:
【中文标题】为啥此代码给出错误【英文标题】:Why this Code is Giving ERROR为什么此代码给出错误 【发布时间】:2014-12-10 12:21:08 【问题描述】:我无法使用简单的 SELECT 语句来初始化变量。
DECLARE
A VARCHAR2(10);
BEGIN
A := (SELECT FIRST_NAME FROM FIMS_OWNER.EMPLOYEE_T WHERE WWID = 'NA734');
END;
/
错误:
[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
【问题讨论】:
【参考方案1】:因为在 Oracle 中,您不能将查询分配给变量。但是,您可以查询变量,如 ...
DECLARE
A VARCHAR2(10);
BEGIN
SELECT FIRST_NAME
INTO A
FROM FIMS_OWNER.EMPLOYEE_T
WHERE WWID = 'NA734';
END;
/
【讨论】:
【参考方案2】:你的代码应该是
DECLARE
A VARCHAR2(10);
BEGIN
SELECT FIRST_NAME INTO A FROM FIMS_OWNER.EMPLOYEE_T WHERE WWID = 'NA734';
END;
您应该使用 INTO 子句将值选择到变量中
【讨论】:
以上是关于为啥此代码给出错误的主要内容,如果未能解决你的问题,请参考以下文章