嵌套表的操作(增删改查)

本文介绍如何在Oracle数据库中创建嵌套表,并演示了包括插入、查询、更新及删除在内的基本操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一,创建嵌套表的步骤:

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';

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值