oracle如何添加行,如何在oracle中向对象类型列添加更多行

本文详细介绍了如何通过嵌套表在Oracle数据库中实现主细节关系的数据存储、插入、更新和查询操作。重点展示了如何利用嵌套表类型和SQL语句来维护和管理复杂的数据结构。然而,它也指出这不是最理想的方法,可能暗示了其他高效解决方案的探讨。
摘要由CSDN通过智能技术生成

要实现这一点,您需要使用嵌套表.这是一个例子:

create or replace type excep_type as object

(

overridden_attribute varchar2 (30),exception_id number

)

/

create or replace type t_excep_type as table of excep_type

/

create table nst_table

(

id number,exp t_excep_type

) nested table exp store as nst_exp -- name of the nested table

/

-- inserting of record in the base table

sql> insert into nst_table(id,exp)

2 values(1,t_excep_type(excep_type('X',1)));

1 row inserted

sql> commit;

Commit complete

sql> select * from nst_table t,table(t.exp);

ID EXP OVERRIDDEN_ATTRIBUTE EXCEPTION_ID

--------------------------------------------- ------------

1

-- inserting of record in the nested table

sql> insert into table(select exp from nst_table where id = 1)

2 values (excep_type('Y','2'))

3 ;

1 row inserted

sql> commit;

Commit complete

-- unnesting.

sql> select * from nst_table t,table(t.exp);

ID EXP OVERRIDDEN_ATTRIBUTE EXCEPTION_ID

---------- --- ------------------------------ ------------

1

1

-- updating of data in the nested table

sql> update table(select exp from nst_table where id = 1)

2 set overridden_attribute = 'Z',exception_id = 3

3 where exception_id = 1 and overridden_attribute = 'X';

1 row updated

sql> select * from nst_table t,table(t.exp);

ID EXP OVERRIDDEN_ATTRIBUTE EXCEPTION_ID

---------- --- -------------------------------------------

1

1

但是,存储数据以实现主 – 细节关系的方法并不是最好的方法.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值