如何在 Oracle Varray 中取 Select 值
How to Select value in Oracle Varray
使用 Oracle 11.2
我已经为 phone 号码创建了一个类型,以便与员工关联....
我正在努力学习语法,不想因为数据库设计的好坏而受到批评...
这是我的 *.sql 文件
CREATE TYPE AddressType AS OBJECT(streetNumber NUMBER(5), StreetName VARCHAR2(30), city VARCHAR2(20));
/
CREATE TYPE empName AS OBJECT(firstname VARCHAR2(10), middle VARCHAR2(10), lastname VARCHAR2(10));
/
CREATE TYPE PhoneNumbers AS OBJECT(phNumb NUMBER(10), numType VARCHAR2(10));
/
CREATE TYPE ContactNumbers AS VARRAY(5) OF PhoneNumbers;
/
CREATE TABLE Workers(eid NUMBER(5), name empName, loc AddressType, contactNums ContactNumbers);
INSERT INTO Workers VALUES( 1,
empName('Ramos', null, 'Phil'),
AddressType(123, 'A Street', 'San Diego'),
ContactNumbers(
PhoneNumbers(1234567890, 'cell'),
PhoneNumbers(2345678901, 'home')
)
);
--Display all members of workers
SELECT * FROM Workers; -- i get something here I'm ok with
--Display all the names
--SELECT (w.name.firstname||' '||w.name.middle||' '||w.name.lastname) as "Name" FROM Workers w; --this works
--Display their location
--SELECT (w.loc.streetNumber||' '||w.loc.StreetName||', '||w.loc.city) as "Location" FROM Workers w; -- this works
--Display their phone numbers
SELECT (w.contactNums(1).phNumb||' <'||w.ContactNumbers(1).numType||'>') as "Phone Numbers" FROM Workers w; -- this line I can't figure out
问:如何写最后一个 SELECT
以便获得 phone 个数字的列表?
我希望我的输出类似于:
phone Numbers
-------------
1234567890 <cell>
2345678901 <home>
在 VARRAY
:
的情况下,您将使用 TABLE
运算符
SELECT e.phNumb||' <'||e.numType||'>' as "Phone Numbers"
FROM Workers w, TABLE(w.contactNums) e;
Phone Numbers
-----------------------------------------------------
1234567890 <cell>
2345678901 <home>
您可以在 Database Oject-Relational Developer's Guide 中找到更多相关信息。
使用 Oracle 11.2
我已经为 phone 号码创建了一个类型,以便与员工关联.... 我正在努力学习语法,不想因为数据库设计的好坏而受到批评...
这是我的 *.sql 文件
CREATE TYPE AddressType AS OBJECT(streetNumber NUMBER(5), StreetName VARCHAR2(30), city VARCHAR2(20));
/
CREATE TYPE empName AS OBJECT(firstname VARCHAR2(10), middle VARCHAR2(10), lastname VARCHAR2(10));
/
CREATE TYPE PhoneNumbers AS OBJECT(phNumb NUMBER(10), numType VARCHAR2(10));
/
CREATE TYPE ContactNumbers AS VARRAY(5) OF PhoneNumbers;
/
CREATE TABLE Workers(eid NUMBER(5), name empName, loc AddressType, contactNums ContactNumbers);
INSERT INTO Workers VALUES( 1,
empName('Ramos', null, 'Phil'),
AddressType(123, 'A Street', 'San Diego'),
ContactNumbers(
PhoneNumbers(1234567890, 'cell'),
PhoneNumbers(2345678901, 'home')
)
);
--Display all members of workers
SELECT * FROM Workers; -- i get something here I'm ok with
--Display all the names
--SELECT (w.name.firstname||' '||w.name.middle||' '||w.name.lastname) as "Name" FROM Workers w; --this works
--Display their location
--SELECT (w.loc.streetNumber||' '||w.loc.StreetName||', '||w.loc.city) as "Location" FROM Workers w; -- this works
--Display their phone numbers
SELECT (w.contactNums(1).phNumb||' <'||w.ContactNumbers(1).numType||'>') as "Phone Numbers" FROM Workers w; -- this line I can't figure out
问:如何写最后一个 SELECT
以便获得 phone 个数字的列表?
我希望我的输出类似于:
phone Numbers
-------------
1234567890 <cell>
2345678901 <home>
在 VARRAY
:
TABLE
运算符
SELECT e.phNumb||' <'||e.numType||'>' as "Phone Numbers"
FROM Workers w, TABLE(w.contactNums) e;
Phone Numbers
-----------------------------------------------------
1234567890 <cell>
2345678901 <home>
您可以在 Database Oject-Relational Developer's Guide 中找到更多相关信息。