如何在oracle中为记录类型编写循环
我有以下语句,可以在我的包中正常编译:
package header:
TYPE role_user_type IS RECORD (
ROLE_ID some_table.ROLE_ID%TYPE,
SUBGROUP some_table.USER_ID%TYPE
);
body:
ROLE_USER_REC MY_PACKAGE.ROLE_USER_TYPE;
SELECT B.USER_ID, B.ROLE INTO ROLE_USER_REC
FROM some_table where user_id like 'M%'
循环 ROLE_USER_REC 的骨架是什么?我们甚至可以循环遍历它吗?
I have the following statement which compiles fine in my package:
package header:
TYPE role_user_type IS RECORD (
ROLE_ID some_table.ROLE_ID%TYPE,
SUBGROUP some_table.USER_ID%TYPE
);
body:
ROLE_USER_REC MY_PACKAGE.ROLE_USER_TYPE;
SELECT B.USER_ID, B.ROLE INTO ROLE_USER_REC
FROM some_table where user_id like 'M%'
what is the skeleton for looping through ROLE_USER_REC
? can we even loop through it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以为此使用游标
You can use cursors for this
没有什么可以循环的。
role_user_type
定义一条记录,您可以通过以下方式访问该记录:一旦返回多行,您的
SELECT ... INTO
将失败。如果您需要存储其中多个记录,可以使用嵌套表,例如
TYPE role_user_tab 是 role_user_type 的表
:示例:
There is nothing to loop.
role_user_type
defines a single record, that you can access via:Your
SELECT ... INTO
will fail as soon as more than one row is returned.If you need to store several of those records, you can use nested tables like
TYPE role_user_tab IS TABLE OF role_user_type
:Example:
您可以使用游标 FOR 循环:
另一种选择:
You can use a cursor FOR loop:
Another alternative: