Oracle 11g 对象数组

发布于 2024-08-21 19:18:30 字数 368 浏览 5 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恋竹姑娘 2024-08-28 19:18:30

我很确定:

  1. 你正在做的事情不是我会做的。它有点完全违反了关系原则,并且您最终将在 Oracle 中得到一个对象/类型系统,一旦确定就可能无法更改。我见过的 SQL 类型(不是 PL/SQL 类型)的最佳用途基本上是能够将引用游标投射回管道函数。

  2. 您必须先解除集合的嵌套,然后才能进行关系查询,如下所示:

    从以下位置选择名称
    (SELECT SP.* FROM PEOPLE P, TABLE(P.SOME_PEOPLE) SP)

这将为您提供所有行,因为您的规范中没有任何内容(如 PERSON_ID 属性)来限制行。

Oracle 应用程序开发人员指南 - 对象关系特性通过示例更深入地讨论了所有这些内容。

I'm pretty sure that:

  1. 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.

  2. 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.

够钟 2024-08-28 19:18:30
To insert query:-

insert into people values (
person_varray(person('Ram','24'))
);

To select :-

select * from people;

SELECT NAME FROM (SELECT SP.* FROM PEOPLE P, TABLE(P.somePeople) SP)

While inserting a row into people table use constructor of 
person_varray and then the constructor 
of person type for each project.
The above INSERT command 
creates a single row in people table.

 select somePeople from people ;

 person(NAME, age) 
---------------------------------------------------
person_varray(person('Ram', 1), 

To update the  query will be:-

update people 
set somePeople =  
           person_varray 
           (  
               person('SaAM','23')  
           ) 
To insert query:-

insert into people values (
person_varray(person('Ram','24'))
);

To select :-

select * from people;

SELECT NAME FROM (SELECT SP.* FROM PEOPLE P, TABLE(P.somePeople) SP)

While inserting a row into people table use constructor of 
person_varray and then the constructor 
of person type for each project.
The above INSERT command 
creates a single row in people table.

 select somePeople from people ;

 person(NAME, age) 
---------------------------------------------------
person_varray(person('Ram', 1), 

To update the  query will be:-

update people 
set somePeople =  
           person_varray 
           (  
               person('SaAM','23')  
           ) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文