本文介绍了在Oracle中交换列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在解决一个难题,并遇到了使用DML查询交换列值的问题:
I was solving one of the puzzles and came across swapping column values using DML queries:
SELECT * FROM TEMP_TABLE;
ID1, ID2
--------
20, 15
20, 15
20, 15
解决方案是数学计算:
UPDATE TEMP_TABLE SET ID1=ID1+ID2;
UPDATE TEMP_TABLE SET ID2=ID1-ID2;
UPDATE TEMP_TABLE SET ID1=ID1-ID2;
现在,我正在尝试确定是否可以将其应用于字符串.
Now, I am trying to figure out whether this can be applied to Strings or not, please suggest.
SELECT * FROM TEMP_TABLE_NEW;
ID1, ID2
--------
ABC, XYZ
ABC, XYZ
ABC, XYZ
推荐答案
不需要三个更新语句,一个就足够了:
There's no need to have three update statements, one is sufficient:
UPDATE temp_table_new
SET id1 = id2,
id2 = id1;
这篇关于在Oracle中交换列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!