一,创建嵌套表的步骤:
1.先创建一个嵌套表基类型
create or replace Type MingXiType as Object
(
Goodsid varchar(13), --货物编号
IntCount int , --入库数量
Provider varchar(13) --提供者
) not final
2.创建一个嵌套表类型:(这是一个基于基类型的嵌套表)
create a replace Type nestMingXiType as Table of MingXiType;
3.创建一个表,将嵌套表作为该表的一个字段
create table instockTable
(
Orderid varchar(13) --订单号,
InDate Date --日期,
Operator varchar(15),-- 操作员
MingXi nestMingXiType --嵌套表类型
) nested table MingXi store as MingXiTable;
-字段名- -真正存储嵌套表名-
二.操作嵌套表
1.向嵌套表中插入记录
insert into instockTable
values ( '200208060002', to_date( '2008-01-01','yyyy-MM-DD'), 3002 ,
nestMingXitype( MingXiType ('j0001' , 200 , '1001'),
MingXiType ('s0001' , 1000, '1002'),
MingXiType ('y0005' , 500 , '1003')
)
);
2.查询表中的记录,使用集合函数 table()可以将其嵌套表搜索出
select * from table( select p.MingXI from instockTable p
where orderid = '200208060001'
); --可以显示嵌套表中的内容
3.更新嵌套表中的数据
update table( select p.mingxi from instockTable p where orderid = '200208060001') mx
set mx.intCount = 500 where mx.goodsid = 'j0001';
4.删除表中的数据
删除嵌套表中的某条数据
delete from table ( select p.mingxi from instock p where orderid = '200208060001') tx
where tx.goodsid = 'j0001';