oracle,在嵌套表中添加一个新行

问题描述 投票:-1回答:2

我有这三个对象

create or replace 
type type_client 
( num int , 
  username varchar(30), 
  balance int, 
  ta table_achat, 
  ref_admin ref type_admin,
  member function get_prix_achat_total return int );



create or replace 
type table_achat as table of achat ;


create or replace 
type achat as object ( num_item int , qte int
);

create table table_client OF type_client ;

假设在table_client的一个条目中..我们有一个这样的嵌套表:

(num_item,qte) : (1 , 5),(2 , 3)

我想要的是嵌套表是这样的(例如):

(num_item,qte) : (1 , 5),(2 , 3)(3 , 44)

我的意思是,如何在保留现有条目的同时向已创建的嵌套表添加新行? ..

oracle user-defined-types
2个回答
2
投票

我们可以使用MULTISET UNION运算符从两个集合中创建一个新集合。在您的情况下,其中一个集合是您现有的集合,第二个集合是新条目集合。

以下是基于简化版设置的演示:

declare
  nt table_achat;
begin
  nt := table_achat(achat(1 , 5),achat(2 , 3));
  dbms_output.put_line(nt.count());

  nt := nt multiset union table_achat(achat(3 , 44));
  dbms_output.put_line(nt.count());
end;
/

给定一个表T42,其列COL_NT是table_achat类型的嵌套表,您可以在嵌套表中插入一个新条目,如下所示:

insert into the 
(select col_nt from t42 where id = 1) 
values (achat(3,44));   

0
投票

与问题无关,我不能也不会试图理解,你不能像以前那样结合insert + select + values语句。也许你可能更喜欢以下的:

insert into the -- if table has one string column
(select ta from table_client where username=user);

OR

insert into the -- if table has two numeric columns
values (3,44);
© www.soinside.com 2019 - 2024. All rights reserved.