将一堆字段提取到包中定义的自定义对象中
假设我有一个包 A
,
type type_bla is record (id number, ...);
在同一个包主体中我还有一个查询,它获取构造对象所需的所有字段。如果我有一个存储的对象,我可以这样做:
select type_bla(t1.id, t2.foo, t1.bar ...)
into instance_of_type_bla
from table t
inner join table2 t2 ON ...
但是由于我在包中定义了一个自定义类型 - 它没有构造函数,所以我不得不将其更改为:
select t1.id, t2.foo, t1.bar ...
into instance_of_type_bla.id, instance_of_type_bla.foo ...
from table t
inner join table2 t2 ON ...
填充此类对象的更优雅的方式吗?
Let's suppose I have a package A
that has
type type_bla is record (id number, ...);
Also in the same package body I have a query, that fetches all the fields needed to construct the object. If I had a stored object I could do:
select type_bla(t1.id, t2.foo, t1.bar ...)
into instance_of_type_bla
from table t
inner join table2 t2 ON ...
But since I have a custom type defined in the package - it has not a constructor, so I obliged to change it to:
select t1.id, t2.foo, t1.bar ...
into instance_of_type_bla.id, instance_of_type_bla.foo ...
from table t
inner join table2 t2 ON ...
Is it more elegant way to fill such sort of objects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够简单地将数据直接选择到记录中,就像声明 %ROWTYPE 记录一样。
我将声明一个包
PKG_FOO
,其中GET_REC
函数填充自定义记录,只是为了表明它有效
You should be able to simply select the data directly into the record just like you would if you declared a %ROWTYPE record.
I'll declare a package
PKG_FOO
where theGET_REC
function populates the custom recordAnd just to show that it works