我在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
谢谢
答案 0 :(得分:3)
我很确定:
你所做的不是我要做的。它完全违反了关系原则,你将最终得到Oracle中的一个对象/类型系统,一旦它被放下,你可能无法改变它。我见过的SQL TYPE(不是PL / SQL类型)的最佳用法基本上是能够为流水线函数强制转换ref游标。
您必须先删除该集合才能对其进行相关查询,如下所示:
SELECT NAME FROM (SELECT SP。* FROM PEOPLE P,TABLE(P.SOME_PEOPLE)SP)
那将为您提供所有行,因为您的规范中没有任何内容(如PERSON_ID属性)来限制行。
Oracle应用程序开发人员指南 - 对象关系功能通过示例更深入地讨论了所有这些内容。
答案 1 :(得分: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')
)