Oracle 存储过程中的 FOR 类型 IN
我有一个名为 fatorial_type 的类型和一个从该类型创建的表因子,当执行下面的代码时,我收到错误“PLS-00302:必须声明组件'SET_NUM_FATORIAL'”,是的,该过程已声明。
SET serveroutput ON format wraped;
DECLARE
fat fatorial_type;
BEGIN
FOR fat IN
(SELECT value(f) FROM fatorial f)
LOOP
fat.SET_NUM_FATORIAL(5);
END LOOP;
END;
如果我
SELECT value(f) into fat FROM fatorial f
这样做是有效的,也许问题与 FOR IN 有关,它不能像 into 那样工作
I have a type called fatorial_type and a table fatorial created from that type, when executing this code below I got the error "PLS-00302: component 'SET_NUM_FATORIAL' must be declared", and yes that procedure was declared.
SET serveroutput ON format wraped;
DECLARE
fat fatorial_type;
BEGIN
FOR fat IN
(SELECT value(f) FROM fatorial f)
LOOP
fat.SET_NUM_FATORIAL(5);
END LOOP;
END;
If I do
SELECT value(f) into fat FROM fatorial f
thats works, maybe the problem is related with FOR IN that don't work like into
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 PL/SQL 中循环结果集有几种略有不同的语法。它们为我们提供了对获取的不同级别的控制。最简单的解决方案是不声明游标变量并让 Oracle 解决问题。但您确实需要在投影中为返回值添加别名。
所以,这是一个带有方法的简单类型...
我们在该类型上创建一个表...
现在让我们开始:
There are several slightly different syntaxes for looping through resultsets in PL/SQL. They give us different levels of control over the fetch. The simplest solution is to not declare a cursor variable and let Oracle resolve things. But you do need to alias the returned value in the projection.
So, here is a simple type with a method ...
We create a table on that type ....
Now let's roll:
它可能会感到困惑,因为您使用“fat”作为变量的名称和隐式游标的名称。
尝试将光标变量更改为“r”
开始
为 r 输入
(从阶乘 f 中选择值(f))
环形
脂肪.SET_NUM_FATORIAL(5); /* 你想用你选择的值做什么? */
结束循环;
结尾;
It's probably confused because you've used "fat" as the name of a variable and the name of the implicit cursor.
try changing the cursor variable to "r"
BEGIN
FOR r IN
(SELECT value(f) FROM fatorial f)
LOOP
fat.SET_NUM_FATORIAL(5); /* what do you want to do with the value you selected? */
END LOOP;
END;