Oracle字符串声明错误

时间:2018-03-02 19:03:37

标签: oracle plsql oracle11g

我很长一段时间没有使用过Oracle。这里有一个简单的问题。

我使用以下变量声明和查询:

declare
new_line := 'LINE_12';
begin
select dept from departments where line = new_line;

我收到此错误:

ORA-06550: line 2, column 11: PLS-00103: Encountered the symbol "=" 
when expecting one of the following: constant exception 
<an identifier> <a double-quoted delimited-identifier> 
table long double ref char time timestamp interval date 
binary national character nchar The symbol "<an identifier>" 
was substituted for "=" to continue. 

1 个答案:

答案 0 :(得分:1)

您尚未声明new_line的数据类型,请将数据类型指定为VARCHAR2(大小)

new_line varchar2(50)DEFAULT:=&#39; LINE_12&#39 ;; 要么 new_line varchar2(50); 根据您的方便分配价值。

并确保您传递的值存在于department表中,否则它将返回NULL。