在PL / SQL中选择对象内的对象

时间:2018-05-25 08:01:32

标签: sql oracle plsql

我有以下代码:

SET SERVEROUTPUT ON

CREATE OR REPLACE TYPE work_t AS OBJECT(
company VARCHAR2(50),
salary NUMBER(5)
);
/

CREATE OR REPLACE TYPE person_t AS OBJECT(
personnum NUMBER(5),
personname VARCHAR2(20),
personwork work_t
);
/

CREATE TABLE people OF person_t(
PRIMARY KEY (personnum)
);

INSERT INTO people VALUES(12, 'George', work_t('Google',75500));  

如果我想打印人名:

DECLARE
per1 person_t;
BEGIN
SELECT VALUE(e) INTO per1 FROM people e WHERE e.personnum = 12;
dbms_output.put_line(per1.personname);
END;
/

现在我想打印公司(并在不同的区块中更新),但我不知道该怎么做。

感谢。

1 个答案:

答案 0 :(得分:0)

添加

dbms_output.put_line(per1.personwork.company);

in

DECLARE
per1 person_t;
BEGIN
SELECT VALUE(e) INTO per1 FROM people e WHERE e.personnum = 12;
dbms_output.put_line(per1.personname);
dbms_output.put_line(per1.personwork.company);
END;
/