0

我想在取消透视后插入数据。该语句需要是一个合并语句。但是,我收到 ora-30926 错误,我真的不知道如何解决它。

这里是数据表:

------------------------------------------------------------------------------------
|Employee_id | work_experience_1 | work_experience_2 | work_experience_3 | language |
-------------------------------------------------------------------------------------
| 123        |  C&S              |   Deloitte        |         TCS       |     FI   |
| 211        |   E&Y             |   Microsoft       |                   |     FI   |
| 213        |   C&S             |                   |                   |     FI   |
-------------------------------------------------------------------------------------

因此,首先在输入数据之前,我需要对其进行反透视。

---------------------------------- 
|Employee_id | work_experience   |
----------------------------------
| 123        |   C&S             |
| 123        |   Deloitte        |
| 123        |     TCS           |
| 211        |   E&Y             |
| 211        |   Microsoft       |
| 213        |   C&S             |
----------------------------------

这是我所做的。插入部分工作正常,但更新部分失败。

MERGE INTO arc_hrcs.user_multi_work_exp work_exp
USING (SELECT user_id, work_experience_lang, work_exp_fi FROM
         (SELECT ext.user_id, tmp_work.employee_id, tmp_work.work_experience_1, tmp_work.work_experience_2, tmp_work.work_experience_3, tmp_work.work_experience_4, tmp_work.work_experience_5, tmp_work.work_experience_6, tmp_work.work_experience_7, tmp_work.work_experience_8, tmp_work.work_experience_9, tmp_work.work_experience_10, tmp_work.work_experience_lang FROM arc_hrcs.hr_extension_data ext
            JOIN aa_work_exp_tmp tmp_work ON tmp_work.employee_id = ext.employee_id) 
            UNPIVOT (work_exp_fi FOR work_code IN (work_experience_1 AS 'a', work_experience_2 AS 'b', work_experience_3 AS 'c', work_experience_4 AS 'd',  work_experience_5 AS 'e', work_experience_6 AS 'f', work_experience_7 AS 'g', work_experience_8 AS 'h', work_experience_9 AS 'i', work_experience_10 AS 'j'))) r
ON (work_exp.user_id = r.user_id AND r.work_experience_lang LIKE '%FI%' )
WHEN NOT MATCHED THEN
     INSERT (work_exp.user_id, work_exp.work_experience_fi)
     VALUES (r.user_id, r.work_exp_fi)
WHEN MATCHED THEN
     UPDATE SET work_exp.work_experience_fi = r.work_exp_fi

我该怎么做才能让它工作?提前干杯和谢谢:-)

4

2 回答 2

0

本质上,USING原因中的查询是多行子查询,当它需要是单行子查询时。我会尝试单独运行子查询并尝试修复 WHERE 原因的逻辑,以便您带回唯一的行。

http://blog.mclaughlinsoftware.com/2010/03/05/stable-set-of-rows/

于 2012-10-29T17:36:43.823 回答
0

afaik,MERGE 语句需要在 ON 子句以及目标表中指定的 UNIQUE 或 PRIMARY KEY 列。查看您的数据样本,您可能在源表中遗漏了它(它们)。

于 2012-08-13T14:22:02.753 回答