Oracle Pl/SQl:具有中间结果的自定义函数
我需要使用一些 Oracle 内置方法(解析、strlength 等)将字符串转换为数字
我不知道如何为方法内的变量赋值,也不知道将声明部分放在哪里。
CREATE OR REPLACE FUNCTION EXAMPLE (param IN VARCHAR2)
RETURN NUMBER AS
BEGIN
SELECT <string_handling_using_param>
INTO var
FROM DUAL;
RETURN TO_NUMBER(<some computation using var>);
END EXAMPLE ;
我已经尝试了围绕此函数的一些变体,例如添加 OUT 参数来存储中间变量,但随后我无法从常规 SQL 调用该函数...
关于如何实现此目的有什么建议吗?
I need to transform a string into a number using some oracle built-in methods (parsing, strlength, ...)
I don't know how to assign a value to a variable inside the method, and I don't know where to put the declare section.
CREATE OR REPLACE FUNCTION EXAMPLE (param IN VARCHAR2)
RETURN NUMBER AS
BEGIN
SELECT <string_handling_using_param>
INTO var
FROM DUAL;
RETURN TO_NUMBER(<some computation using var>);
END EXAMPLE ;
I have tried some variation around this function, like adding an OUT parameter for storing the intermediate var, but then I can not call the function from regular SQL...
Any suggestion on how to achieve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我理解正确,您只需要定义“var”变量...
具体取决于您正在做的事情,可能有一种更好的方法不需要 SELECT ... FROM DUAL:
If I understand correctly you just need to define the "var" variable...
Depending on exactly what you're doing, there may be a better approach that doesn't need the SELECT ... FROM DUAL: