我有两个表和一个函数,
表1包含shop_code,batch_id,registry_id
shop_code| batch_id|registry_id
123 | 100 |12
124 | 100 |13
125 | 100 |12
表2 contains shop_code,shop_name
shop_code| shop_name
123 | need to populate
124 | need to populate
125 | need to populate
Function1从table1获取参数registry_id
并返回shop_name
Table2 shop_name为空我想填充shop_code。
我尽了最大的努力,但所有的努力都是徒劳的 如果有人可以帮助我使用Oracle,那将会很棒。
我尝试了以下代码,但是从关键字
中提出了错误 update TABLE2 set T2.SHOP_NAME = T.SHOP_NAME
from(
select GET_shop_name(t1.registry_id) as shop_name ,
t1.shop_code shop_code
from TABLE1 T1
) t where t.shop_code = t1.shop_code;
答案 0 :(得分:2)
如果我的问题得到解决,我并非完全100%确定,但我相信你想要像
这样的东西update
table2 u
set
shop_name = (
select
get_shop_name(t1.batch_id)
from
table1 t1
where
t1.chop_code = u.shop_code
);
答案 1 :(得分:2)
你可以尝试这种方法尝试将内部查询设置为获取商店名称值;我没有测试过,但我认为方法对你有用。
update TABLE2 T2
set T2.SHOP_NAME =
(select GET_shop_name(t1.batch_id, t1.shop_code) from table1 t1 wehre t1.shop_code = t2.shop_code)
where T2.shop_name is null
答案 2 :(得分:1)
您需要MERGE声明。
这样的事可能有用:
MERGE INTO TABLE2 t2
USING (
SELECT GET_shop_name(t1.batch_id) AS shop_name ,
t1.shop_code shop_code
FROM TABLE1 T1 ) t1
ON (t2.shop_code = t1.shop_code)
WHEN MATCHED THEN
UPDATE SET t2.shop_name = t1.shop_name
;
如果上面的确切代码不起作用,您将不得不原谅我没有SQL Dev我现在正在寻找语法细节。 :)