Oracle 11g 对象数组
我在 Oracle 11g 中有以下语句:
CREATE TYPE person AS OBJECT (
name VARCHAR2(10),
age NUMBER
);
CREATE TYPE person_varray AS VARRAY(5) OF person;
CREATE TABLE people (
somePeople person_varray
)
How can i select the name value for a person 即
SELECT somePeople(person(name)) FROM people
谢谢
I have the following statements in Oracle 11g:
CREATE TYPE person AS OBJECT (
name VARCHAR2(10),
age NUMBER
);
CREATE TYPE person_varray AS VARRAY(5) OF person;
CREATE TABLE people (
somePeople person_varray
)
How can i select the name value for a person i.e.
SELECT somePeople(person(name)) FROM people
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很确定:
你正在做的事情不是我会做的。它有点完全违反了关系原则,并且您最终将在 Oracle 中得到一个对象/类型系统,一旦确定就可能无法更改。我见过的 SQL 类型(不是 PL/SQL 类型)的最佳用途基本上是能够将引用游标投射回管道函数。
您必须先解除集合的嵌套,然后才能进行关系查询,如下所示:
从以下位置选择名称
(SELECT SP.* FROM PEOPLE P, TABLE(P.SOME_PEOPLE) SP)
这将为您提供所有行,因为您的规范中没有任何内容(如 PERSON_ID 属性)来限制行。
Oracle 应用程序开发人员指南 - 对象关系特性通过示例更深入地讨论了所有这些内容。
I'm pretty sure that:
What you're doing isn't what I'd be doing. It sort of completely violates relational principles, and you're going to end up with an object/type system in Oracle that you might not be able to change once it's been laid down. The best use I've seen for SQL TYPEs (not PL/SQL types) is basically being able to cast a ref cursor back for pipelined functions.
You have to unnest the collection before you can query it relationally, like so:
SELECT NAME FROM
(SELECT SP.* FROM PEOPLE P, TABLE(P.SOME_PEOPLE) SP)
That'll give you all rows, because there's nothing in your specifications (like a PERSON_ID attribute) to restrict the rows.
The Oracle Application Developer's Guide - Object Relational Features discusses all of this in much greater depth, with examples.