Oracle - 对象关系数据库(将Ref引入INTO子类型到另一个对象)

时间:2011-11-08 18:35:21

标签: sql database oracle

基本上,我有一个超类型(Person)和子类型(Student)。我必须在person_objtab中插入一个学生对象。一个person对象有一个REF to Address表,当我试图添加新学生时,它给了我'缺少表达'错误。这是代码,非常感谢任何帮助!

create type address_objtyp as object (
    Line1 varchar2(30),
    Line2 varchar2(30),
    Line3 varchar2(30),
    Postcode varchar2(10),
    Country varchar2(20)
)
/

create type person_objtyp as object (
    NI varchar2 (20),
    Name varchar2(30),
    Address REF address_objtyp,
    Phone varchar2(30)
)
NOT FINAL
/

CREATE type student_objtyp UNDER person_objtyp (
    Dept_id varchar2(10),
    Course varchar2(10),
    StuYear number,
    Total_credits number
)
/

create table address_objtab of address_objtyp;
create table person_objtab of person_objtyp;

INSERT INTO address_objtab VALUES(
address_objtyp('9',  'Bell', 'Lancashire', ' BB52 4GF', 'the UK')
)
/

这是失败的陈述:

INSERT INTO Person_objtab values 
 (student_objtyp 
     (SELECT  2222, 'Jo', REF(aa), '0161 0450 452', '10', 'Computing', '2', 220 
       FROM address_objtab aa
      WHERE aa.postcode = ' BB52 4GF')
)
/

2 个答案:

答案 0 :(得分:0)

你混淆了立即值和结果集插入的语法,对象构造函数需要在select子句中 - 试试

INSERT
  INTO Person_objtab (
           SELECT student_objtyp( 2222, 'Jo', REF(aa), '0161 0450 452', '10', 'Computing', '2', 220)
             FROM address_objtab aa 
            WHERE aa.postcode = ' BB52 4GF'
       )
     ;

代替。问候,卡斯滕

答案 1 :(得分:0)

INSERT INTO person_objtab 
VALUES (student_typ(
        2222,
        'Jo',
        (SELECT REF(b) FROM address_objtab b WHERE line1 = '9 Bell'),
         '01200 233 233',
         10,
         'Computing',
         2,
         220
));