博客文章除注明转载外,均为原创。转载请注明出处。
本文链接地址:http://blog.chinaunix.net/uid-31396856-id-5786380.html
开发反映说,执行一个脚本报错全是undo的错误,收到脚本全是如下类似语句
update LLxxx a set bankcode= nvl(( select code1 from ldcode1
where codetype='xxxxxx'
and a .bankcode=xxcode1.code),a.bankcode)
where a.bankcode is not null;
这类语句。
下面上执行计划
这类语句通常用merge into语句来优化。
merge into的应用场景:
一段业务逻辑,需要先判断一条记录在数据库中是否有存在,若存在则更新该记录,若不存在则插入记录。
语法:
MERGE INTO table_name alias1
USING (table|view|sub_query) alias2 ON (join condition) WHEN MATCHED THEN UPDATE table_name SET col1 = col_val1,
col2 = col_val2 WHEN NOT MATCHED THEN INSERT (column_list) VALUES (column_values);
修改为如下:
merge into LLXXX A using (select b.code1,c.CLMNO, c."POLNO", c."BATNO", c."BNFKIND", c."INXXXNO", c."BNFNO",
c."CASENO", c."FEEXXXXTYPE", c."CURRENCY" from LLCODE1 b,LLXXX c where b.codetype='BankCodeToZJXT'
and c.bankcode=b.code and c.bankcode is not null) d on
(A."POLNO"=d."POLNO"
and A."BATNO"=d."BATNO"
and A."BNFKIND" = d."BNFKIND"
and A."INXXXNO"=d."INXXXNO"
and A."BNFNO"=d."BNFNO"
and A."CASENO"=d."CASENO"
and A."FEEXXXXTYPE"=d."FEEXXXXTYPE"
and A."CURRENCY"=d."CURRENCY")
WHEN MATCHED THEN
UPDATE set A.bankcode= d.code1;
执行计划如下:
收工
--The End
阅读(30455) | 评论(0) | 转发(0) |