我正在使用
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
我想声明一个变量,以便以后使用它。这就是我所做的:
DECLARE
price myBeer VARCHAR(20);;
这会导致错误:
[DECLARE - 0 row(s), 0.000 secs] [Error Code: 6550, SQL State: 65000] ORA-06550: Row 2, Column 22:
PLS-00103: found symbol "end-of-file" while expecting one of the following: := ; not null default character
这让我做了以下事情:
DECLARE
myBeer VARCHAR(20) :=2;
但这也会导致错误:
[DECLARE - 0 row(s), 0.000 secs] [Error Code: 6550, SQL State: 65000] ORA-06550: Row 2, Column 26:
PLS-00103: found symbol "end-of-file" while expecting one of the following: * & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like like2 like4 likec between || multiset member submultiset
这真的很难吗?
答案 0 :(得分:4)
您必须立即编译整个块,并且变量仅在BEGIN ... END
块的范围内有效:
DECLARE
myVariableName VARCHAR2(4000);
BEGIN
myVariableName := 'TEST';
DBMS_OUTPUT.PUT_LINE( 'Value of var = ' || myVariableName ); -- This works!
END;
/
-- This will not work, since it is outside of the Block!
SELECT myVariableName FROM DUAL;
答案 1 :(得分:1)
以下代码对我很有用:
DECLARE
price VARCHAR(20);
begin
null;
end;
好像你的代码在语法上不正确。
编辑 - 我发布此代码只是为了让它编译。</ p>