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

发布于 2024-10-11 18:28:54 字数 296 浏览 2 评论 0原文

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

我有这样的事情:

FUNCTION some_function
(
t_string IN VARCHAR2
) RETURN NUMBER IS

some_variable NUMBER;

BEGIN
//logic
END some_function;

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

非常感谢, 河豚

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.

Many thanks,
Fugu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海螺姑娘 2024-10-18 18:28:54

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

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

BEGIN

return some_variable;

END some_function;

按预期返回 NULL:

select some_function('ff') from dual  

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:

select some_function('ff') from dual  
薄情伤 2024-10-18 18:28:54

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文