[英]how can I take two tables and merge them into a third without a “temp” table?
I have a few oracle strings that is doing a merge and an inset and then merge. 我有几个oracle字符串正在执行合并和插入,然后合并。 I got it to work this way but due to company restrictions, adding tables takes at least two weeks.
我让它以这种方式工作,但是由于公司的限制,添加表至少需要两周时间。 (I made the site_item_temp table just to get this command set to work.) The oracle Server does not have this table and we cannot sit and wait while the DBAs take their time adding the table, or any table that is with the proper privileges and such.
(我制作了site_item_temp表只是为了将此命令设置为起作用。)oracle服务器没有该表,我们无法坐等DBA花时间添加表或具有适当特权的任何表,并且这样。
I need this to run without hitting the site_item_temp table, or any other table except those listed. 我需要运行它而无需点击site_item_temp表或除列出的表以外的任何其他表。 due to DBA's restrictions/time limits.
由于DBA的限制/时间限制。 I'm scratching my head with this.
我为此抓挠头。 it is probably very simple but I'm just drawing a blank.
这可能非常简单,但我只是在画一个空白。
Here are the scripts I run. 这是我运行的脚本。
MERGE INTO SITE_ITEM_MASTER D
USING ITEM_MST S
ON (D.SKU = S.INVEN_ID
and d.loc_id = s.loc_id)
WHEN NOT MATCHED THEN
INSERT (D.SKU, D.CASES_PER_PALLET, D.LOC_ID)
VALUES (S.INVEN_ID, S.CASE_PER_PAL_QTY, S.LOC_ID);
DELETE FROM SITE_ITEM_TEMP;
INSERT INTO SITE_ITEM_TEMP ( SKU, CASES_PER_PALLET, LOC_ID )
SELECT ITEM_MST.INVEN_ID, AVG(ITEM_MST.CASE_PER_PAL_QTY) AS AVGOFCASE_PER_PAL_QTY,
ICAM_LOCATIONS.LOCATION_ID
FROM ITEM_MST, ICAM_LOCATIONS
GROUP BY ITEM_MST.INVEN_ID, ICAM_LOCATIONS.Location_ID;
MERGE INTO SITE_ITEM_MASTER D
USING SITE_ITEM_TEMP S
ON (D.SKU = S.SKU
AND D.LOC_ID = S.LOC_ID)
WHEN NOT MATCHED THEN
INSERT (D.SKU, D.CASES_PER_PALLET, D.LOC_ID)
VALUES (S.SKU, S.CASES_PER_PALLET, S.LOC_ID);
DELETE FROM SITE_ITEM_TEMP;
thank you. 谢谢。
merge into site_item_master d
using item_mst s
on (d.sku = s.inven_id
and d.loc_id = s.loc_id)
when not matched then
insert (d.sku, d.cases_per_pallet, d.loc_id)
values (s.inven_id, s.case_per_pal_qty, s.loc_id);
merge into site_item_master d
using (
select item_mst.inven_id sku, avg(item_mst.case_per_pal_qty) as cases_per_pallet, icam_locations.location_id loc_id
FROM ITEM_MST, ICAM_LOCATIONS
group by item_mst.inven_id, icam_locations.location_id
) s
on (d.sku = s.sku and d.loc_id = s.loc_id)
when not matched then
insert (d.sku, d.cases_per_pallet, d.loc_id)
values (s.sku, s.cases_per_pallet, s.loc_id);
You can use subqueries for USING. 您可以将子查询用于USING。 I just replaced tmp table with you select (used for insert into tmp)
我只是用您选择的替换了tmp表(用于插入tmp)
Actually, you don't need a MERGE 实际上,您不需要合并
insert into site_item_master (sku, cases_per_pallet, loc_id)
select inven_id, case_per_pal_qty, loc_id from(
select inven_id, case_per_pal_qty, loc_id
from item_mst
union all
select item_mst.inven_id sku, avg(item_mst.case_per_pal_qty), icam_locations.location_id
from item_mst, icam_locations
group by item_mst.inven_id, icam_locations.location_id
) s
where not exists (select 1 from site_item_master d where d.sku = s.inven_id and d.loc_id = s.loc_id);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.