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
)

我如何选择一个人的姓名值,即

SELECT somePeople(person(name)) FROM people

谢谢

4

2 回答 2

3

我很确定:

  1. 你做的不是我要做的。它有点完全违反了关系原则,并且您最终会在 Oracle 中使用一个对象/类型系统,一旦它被设置,您可能无法更改它。我见过的 SQL TYPE(不是 PL/SQL 类型)的最佳用途基本上是能够将 ref 游标转换回流水线函数。

  2. 您必须先取消嵌套集合,然后才能进行相关查询,如下所示:

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

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

Oracle Application Developer's Guide - Object Relational Features 更深入地讨论了所有这些,并附有示例。

于 2010-02-15T17:44:33.963 回答
0
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')  
           ) 
于 2016-06-06T12:51:23.840 回答