我听说使用 %ROWTYPE 属性在 PL/SQL 中定义记录是一个很好的做法。 这样可以节省打字时间,并且即使添加或删除列,您的包也可以继续运行。 (如果我错了,请纠正我!)
但是,当我从涉及连接的游标中获取数据时,我发现我必须获取程序员定义的记录,其中包括一个(很可能很长)手写列表连接返回的每一列。
所以我的问题是:
是否可以获取嵌套记录,或者获取记录列表,或者做一些事情来避免这种丑陋的混乱? 我尝试过的所有操作都会导致记录与游标返回的内容不匹配的错误。
使用游标返回连接结果对我来说似乎是一个常见的用例,奇怪的是在搜索中没有出现与此相关的任何内容。
谢谢。
I've heard that it's a good practice to define your records in PL/SQL by using the %ROWTYPE attribute. This saves typing and allows your package to continue functioning even when a column is added or deleted. (Correct me if I'm wrong!)
However, when I am fetching from a cursor that involves a join, I find that I have to fetch into a programmer-defined record that includes a (quite-possibly long) hand-written list of every column returned by the join.
So my question is:
Is it possible to fetch into nested records, or fetch into a list of records, or do something to avoid such an ugly kludge? Everything I've tried leads to an error about the record not matching what's being returned by the cursor.
Returning the result of a join using a cursor seems like such a common use-case to me that it's strange that nothing related to this comes up in a search.
Thank you.
发布评论
评论(2)
您可以使用cursor%rowtype。
样本:
You can user cursor%rowtype.
Sample:
为什么还要费心游标声明呢?
这是等价的。
我在你的评论中看到你提到了这一点。 但我看到显式游标语法使用得太多,我认为展示它很重要。
Why even bother with the cursor declaration?
This is equivalent.
I see in your comment you mention this. But I see the explicit cursor syntax used so much, i think it's important to show.