我正在努力将以下更新语句转换为select语句。我希望你能提供一些关于如何转换它的提示。
UPDATE inventory_part_tab
SET planner_buyer = (SELECT hb.buyer_code
FROM info.hb_pur_plan_upd1 hb
WHERE hb.part_no = inventory_part_tab.part_no
AND hb.contract = inventory_part_tab.contract),
last_activity_date = DECODE(contract, '01', TO_DATE(SYSDATE), '06', (TO_DATE(SYSDATE) - (3 / 24)), '20', TO_DATE(SYSDATE), '21', TO_DATE(SYSDATE)),
rowversion = DECODE(contract, '01', SYSDATE, '06', (SYSDATE-(3 / 24)), '20', SYSDATE, '21', SYSDATE, '12', (SYSDATE + (6 / 24)))
WHERE contract IN ('01', '06', '20', '21')
AND prime_commodity NOT IN ('SPCSL','SPCKT','SPCCC','SPCGK','SPCMT')
AND planner_buyer <> (SELECT hb.buyer_code
FROM info.hb_pur_plan_upd1 hb
WHERE hb.part_no = inventory_part_tab.part_no
AND hb.contract = inventory_part_tab.contract)
AND EXISTS (SELECT *
FROM info.hb_pur_plan_upd1 hb
WHERE hb.part_no = inventory_part_tab.part_no
AND hb.contract = inventory_part_tab.contract);
COMMIT;
答案 0 :(得分:0)
转换更新声明:
UPDATE tbl
SET a = foo
, b = bar
WHERE stuff
到select语句,执行以下操作:
SELECT foo AS a
, bar AS b
-- , any other column from tbl you want, e.g. an ID
FROM tbl
WHERE stuff
这真的很简单。
答案 1 :(得分:0)
UPDATE <TABLENAME>
SET <fieldName> = <value>
WHERE <conditons>
将是
SELECT (<value>) as <fieldName
FROM <TABLENAME>
WHERE <conditons>
在这种情况下,<value>
是一个大子查询,但工作方式相同,只需添加括号。