oracle 在 pl/sql 过程中声明变量时出现语法错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12786312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
syntax error when declaring variables in a pl/sql procedure
提问by DavidG
This is sending me a bit mad. I'm trying to add in a variable to a procedure, but it wasn't working - I just got this error message:
这让我有点生气。我正在尝试向过程中添加一个变量,但它不起作用 - 我刚刚收到此错误消息:
[Error] Syntax check (25: 7): ERROR line 25, col 7, ending_line 25, ending_col 12, Found 'number', Expecting: ; -or- .. := DEFAULT NOT NULL -or- % -or- ( . @
[错误] 语法检查 (25: 7): ERROR line 25, col 7,ending_line 25,ending_col 12, Found 'number', Expecting: ; -or- .. := DEFAULT NOT NULL -or- % -or- ( . @
I knocked up a really basic procedure below to isolate the problem and now I'm completely stuck, as every basic syntax guide I've looked as says to do what I've done. Why can't i declare variables as shown below? I normally code in SQL Server if that's any clue as to my problem. Many thanks if anyone can help!
我在下面编写了一个非常基本的程序来隔离问题,现在我完全卡住了,因为我看过的每个基本语法指南都说要做我所做的。为什么我不能声明如下所示的变量?如果这对我的问题有任何线索,我通常会在 SQL Server 中编码。如果有人能帮忙,非常感谢!
CREATE OR REPLACE PROCEDURE MRCS.pro_xxx_test1 (cats out sys_refcursor)
IS
declare
spoon number;
balls varchar2(3);
BEGIN
open cats for select * from dual;
end;
/
回答by cagcowboy
Remove the "DECLARE". Not needed in a function / procedure declaration
删除“声明”。在函数/过程声明中不需要
回答by WBAR
CREATE OR REPLACE PROCEDURE MRCS.pro_xxx_test1 (cats out sys_refcursor)
IS
spoon number;
balls varchar2(3);
BEGIN
open cats for select * from dual;
end;
/
回答by sandeep gupta
Declare local varibale between IS and BEGIN block for procedure and function.
在过程和函数的 IS 和 BEGIN 块之间声明局部变量。
CREATE OR REPLACE PROCEDURE MRCS.pro_xxx_test1 (cats out sys_refcursor) IS spoon number; balls varchar2(3);
创建或替换程序 MRCS.pro_xxx_test1 (cats out sys_refcursor) 是勺子号;球 varchar2(3);
BEGIN
开始
open cats for select * from dual;
为 select * from dual 打开猫;
end;
结尾;
/
/