我试图将某些数据从一个表(table1
)插入另一个表(table2
),就像数据是否存在一样,只需更新数据或插入数据。但我现在面临的问题是,当我添加最后一个条件时如果 first_name like 'mss%' 我必须插入 SERVICE_TYPE_ID 10 否则 20。但是对于这种情况并没有发生这种情况,并且所有情况都成功。所以我想知道最后一种情况有什么问题
trim(b.first_name) like 'mss%'
THEN 10
ELSE 20
这主要是合并更新部分失败并插入 20 而不是 10 这是我的完整 oracle 查询
MERGE INTO table2 a
USING table1 b ON (a.second_name = b.first_name)
WHEN MATCHED THEN
UPDATE
SET a.friendly_name = TRIM(b.friendly_name),
a.account_number = TRIM(b.account_no),
a.ne_type = TRIM(b.ci_type),
a.service_type_id = CASE
WHEN upper(trim(b.company_name)) LIKE '%MWAN%'
OR upper(trim(b.company_name)) LIKE '%MGWAN%'
OR upper(trim(b.company_name)) LIKE '%MWLAN%'
OR upper(trim(b.company_name)) LIKE '%MLAN%'
OR upper(trim(b.company_name)) LIKE '%DDOS%'
OR trim(b.first_name) LIKE 'mss%'
THEN 10 ELSE 20 END,
a.to_locate_in_gis ='Y'
WHERE a.account_number <> b.account_no
WHEN NOT MATCHED THEN
INSERT (ne_slno, second_name, company_id, ne_type, ne_status, service_type_id)
VALUES (s_node_seq_nextval,
TRIM(b.first_name), TRIM(b.company_id),
TRIM(b.ci_type), TRIM(b.ci_status),
CASE
WHEN upper(trim(b.company_name)) LIKE '%MWAN%'
OR upper(trim(b.company_name)) LIKE '%MGWAN%'
OR upper(trim(b.company_name)) LIKE '%MWLAN%'
OR upper(trim(b.company_name)) LIKE '%MLAN%'
OR upper(trim(b.company_name)) LIKE '%DDOS%'
OR trim(b.first_name) LIKE 'mss%'
THEN 10 ELSE 20 END)
WHERE SUBSTR(b.first_name, 1, 1) != ' '
除了指出的情况外,所有情况条件都是成功的trim(b.first_name) like 'mss%'