我的类型和表格如下,
create type investments_type as object(
company ref stocks_type,
purchase_price number(12,2),
date_purchased date,
qty number
);
create type investments_table_type as table of investments_type;
create type clients as object(
client_name varchar(50),
address address_type,
investments investments_table_type
);
create table clients_table of clients
NESTED TABLE investments STORE AS investments_table;
现在我要做的是根据qty
更新investments_type
中的date_purchased
。
我试过像这样做,
update clients_table
set investments = CAST(MULTISET(
select investments_type(company,purchase_price,date_purchased,qty+100)
from table(investments) i
where i.date_purchased < '01-MAR-00') as investments_table_type)
但是这会替换表中的所有其他值。
如何只更新满足where条件的行的qty值而不替换任何其他行?
修改
这就是我设法做到的。
update table(select c.investments
from clients_table c) i
set i.qty = i.qty + 100
where i.date_purchased < '01-MAR-00';
答案 0 :(得分:0)
您可以将对象类型转换为表格并更新此表格。它看起来像这样(未经测试):
update
(select purchase_price, date_purchased, qty
from clients_table
natural join table(investments)
where date_purchased < '01-MAR-00')
set qty = qty + 100;
我身边的小提示:当你想要了解Oracle对象类型时,从更简单的结构开始,而不是“对象表的对象对象”