【发布时间】:2020-12-10 07:10:12
【问题描述】:
是否有可能合并 if 块并从下面创建单个块。两者在逻辑上是相连的。
如果它是 p_update_mode 是 FUll 那么我必须添加为 P_entity_type 传递的表的所有数据。如果它是增量的,那么我已经将连接条件添加到添加选定的添加。此外,如果 p_entity_type 为 null,那么我们必须为 item 和 org 表添加数据。
CREATE OR REPLACE PROCEDURE update_dynamic_entity(p_entity_type VARCHAR2 DEFAULT NULL,
p_update_mode VARCHAR2) IS
BEGIN
IF lower(p_update_mode) = 'incremental'
THEN
INSERT INTO dynamicentitygtt
(entity_type, entity_id, entity_code, synonyms, action)
WITH data_view AS
( -- ITEM table
SELECT 'ITEM' entity_type, -- This separates inserted values
item_id data_id,
item_name data_name,
item_desc data_desc,
creation_date
FROM itemde
UNION ALL
-- ORG table
SELECT 'ORG' entity_type, -- This separates inserted values
org_id,
org_name,
org_desc,
creation_date
FROM orgde
-- NEXT entity table
)
SELECT upper(t.entity_type),
t.data_id,
t.data_name,
t.data_desc,
CASE
WHEN t.creation_date > b.max_last_update_date THEN
'update'
WHEN t.creation_date < b.max_last_update_date THEN
'add'
END
FROM data_view t
JOIN batch_run_details b
ON b.entity_type = t.entity_type
WHERE upper(p_entity_type) = t.entity_type
OR p_entity_type IS NULL;
END IF;
IF UPPER(UPDATE_MODE)='FULL' then
INSERT INTO dynamicentitygtt
(entity_type, entity_id, entity_code, synonyms, action)
WITH data_view AS
(
SELECT 'ITEM' entity_type, -- This separates inserted values
item_id data_id,
item_name data_name,
item_desc data_desc,
'add' action
FROM itemde
UNION ALL
-- ORG table
SELECT 'ORG' entity_type, -- This separates inserted values
org_id,
org_name,
org_desc,
'add' action
FROM orgde
)
SELECT upper(entity_type), data_id, data_name, data_desc,action
FROM data_view
WHERE upper(p_entity_type) = entity_type
OR p_entity_type IS NULL;
END IF;
END update_dynamic_entity;
【问题讨论】: