我有一个阶段表“ STAGE_TABLE
”,其中包括以下值(列是 varchar2,除了 ids)-
+-------------------------------------------------------------------------------------------------------------------------
¦ STAGE_ID ¦ EMP_ID ¦ ATTR1_OLD_VAL ¦ ATTR1_NEW_VAL ¦ ATTR2_OLD_VAL ¦ ATTR2_NEW_VAL ¦ ATTR3_OLD_VAL ¦ ATTR3_NEW_VAL ¦
¦-----------+------------+---------------+---------------+---------------+---------------+---------------+---------------¦
¦ 1 ¦ E001 ¦ xyz ¦ pqr ¦ mmm ¦ nnn ¦ zzz ¦ aaa ¦
¦ 2 ¦ E001 ¦ ¦ ¦ ¦ ¦ ¦ ¦
¦ 3 ¦ E001 ¦ pqr ¦ abc ¦ xxx ¦ yyy ¦ ¦ ¦
¦ 4 ¦ E002 ¦ aaa ¦ ccc ¦ bbb ¦ ttt ¦ ¦ ¦
¦ 5 ¦ E002 ¦ ¦ ¦ ¦ ¦ fff ¦ ppp ¦
¦ 6 ¦ E002 ¦ ¦ ¦ kkk ¦ jjj ¦ ¦ ¦
+-------------------------------------------------------------------------------------------------------------------------
我想将属于同一员工的上表中的多行合并为一个-
+-------------------------------------------------------------------------------------------------------------
¦ EMP_ID ¦ ATTR1_OLD_VAL ¦ ATTR1_NEW_VAL ¦ ATTR2_OLD_VAL ¦ ATTR2_NEW_VAL ¦ ATTR3_OLD_VAL ¦ ATTR3_NEW_VAL ¦
¦------------+---------------+---------------+---------------+---------------+---------------+---------------¦
¦ E001 ¦ pqr ¦ abc ¦ xxx ¦ yyy ¦ zzz ¦ aaa ¦
¦ E002 ¦ aaa ¦ ccc ¦ kkk ¦ jjj ¦ fff ¦ ppp ¦
+-------------------------------------------------------------------------------------------------------------
我开始了解 MERGE 语句,但不确定它是否会起作用。我是 oracle pl/sql 的新手。