提前道歉,我偶尔会有Oracle用户。我已经将各种函数/过程使用的查找表放在一起,并且需要每天使用需要删除或插入的行来刷新一次。我已经将以下简单的查询放在一起,这些查询返回了我可以确定所需操作的列。一旦我返回了删除数据,我就需要从表A中删除site_id和zone_ids匹配的所有记录。我无法找到实现这一目标的最佳方法,我已经考虑将select语句作为游标运行,但我不确定如何使用返回的每条记录中的site_id和zone_id从表A中删除行。
SELECT site_id,zone_id,upper(ebts_switch_name)
FROM Table_A
minus
(SELECT site_id,zone_id, upper(ebts_switch_name)
FROM Table_B@remote_db
UNION
SELECT site_id,zone_id,upper(ebts_switch_name)
FROM Table_C);
SELECT cluster_id, site_id,zone_id, upper(trigram),upper(ebts_switch_name)
FROM Table_B@remote_db
WHERE site_id is NOT NULL
minus
SELECT cluster_name,site_id,zone_id,upper(trigram),upper(ebts_switch_name)
FROM Table_A
答案 0 :(得分:2)
您可以按以下方式直接使用您的陈述:
DELETE FROM TABLE_A
WHERE (SITE_ID, ZONE_ID, UPPER(EBTS_SWITCH_NAME)) IN
(SELECT site_id, zone_id, upper(ebts_switch_name)
FROM Table_A
minus
(SELECT site_id, zone_id, upper(ebts_switch_name)
FROM Table_B@remote_db
UNION
SELECT site_id, zone_id, upper(ebts_switch_name)
FROM Table_C));
INSERT INTO TABLE_A (CLUSTER_NAME, SITE_ID, ZONE_ID, TRIGRAM, EBTS_SWITCH_NAME)
SELECT cluster_id, site_id, zone_id, upper(trigram), upper(ebts_switch_name)
FROM Table_B@remote_db
WHERE site_id is NOT NULL
minus
SELECT cluster_name, site_id, zone_id, upper(trigram), upper(ebts_switch_name)
FROM Table_A;
祝你好运。
答案 1 :(得分:1)
我无法理解第一次查询的含义,因为它与
几乎相同SELECT *
FROM table_a
MINUS
SELECT *
FROM table_a
表示空记录集。
但一般情况下,请使用DELETE
语法
DELETE
FROM table_a
WHERE (col1, col2) IN (SELECT col1, col2
FROM table_b);
INSERT
语法
INSERT INTO table_a (col1, col2)
SELECT col1, col2
FROM table_b;