oracle 我似乎无法在 pl/sql 函数中声明变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4668492/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:25:49  来源:igfitidea点击:

I can't seem to declare variables within a pl/sql function?

oraclesyntaxplsql

提问by Fugu

This is a really simple question, but I can't seem to find the syntax for this anywhere.

这是一个非常简单的问题,但我似乎无法在任何地方找到它的语法。

I have something like this:

我有这样的事情:

FUNCTION some_function
(
t_string IN VARCHAR2
) RETURN NUMBER IS

some_variable NUMBER;

BEGIN
//logic
END some_function;

It hits the some_variable declaration and tells me it was expecting "language" where/how do I declare variables? I've seen examples which have done it this way but for some reason it doesn't work.

它点击 some_variable 声明并告诉我它期待“语言”在哪里/如何声明变量?我见过这样的例子,但由于某种原因它不起作用。

Many thanks, Fugu

非常感谢,府谷

回答by Michael Pakhantsov

Did not found anything wrong with your declared variable:

没有发现您声明的变量有任何问题:

create or replace FUNCTION some_function
(
t_string IN VARCHAR2
) RETURN NUMBER 
IS
some_variable NUMBER;

BEGIN

return some_variable;

END some_function;

Returned NULL as expected:

按预期返回 NULL:

select some_function('ff') from dual  

回答by DCookie

The problem is that you don't have the CREATE OR REPLACE keywords in your function declaration, as shown in @Michael's answer.

问题是您的函数声明中没有 CREATE OR REPLACE 关键字,如@Michael 的回答所示。