我有以下SQL代码(这是我到目前为止做的多少):
MERGE INTO SCHEMA_1.TABLE_1 table1
USING
(
SELECT *
FROM SCHEMA_2.TABLE_2 table2
LEFT JOIN SCHEMA_2.VIEW_1 view1
ON table2.COLUMN_4 = view1.COLUMN_1
)t2
ON(table1.COLUMN_2 = t2.COLUMN_5)
WHEN MATCHED THEN UPDATE SET
table1.COLUMN_3 = t2.COLUMN_6
where table1.COLUMN_2 in
(
select
table1.COLUMN_2
from
SCHEMA_1.TABLE_1 table1,
SCHEMA1.TABLE_3 table3,
SCHEMA1.TABLE_4 table4,
SCHEMA1.TABLE_5 table5,
SCHEMA1.TABLE_6 table6,
SCHEMA1.TABLE_7 table7
where
table4.COLUMN_7 = table3.COLUMN_8 and
table5.COLUMN_9 = table4.COLUMN_10 and
table5.COLUMN_11 = table1.COLUMN_12 and
table4.COLUMN_13 = table7.COLUMN_14 and
table7.COLUMN_15 = table6.COLUMN_16 and
table6.COLUMN_17 = 'DOL' and
table4.COLUMN_18 = 1 and
table1.COLUMN_2 is not null and
table1.COLUMN_3 is null
order by
table1.COLUMN_19 desc
);
但是我收到以下错误消息:
SQL Error: ORA-00907: missing right parenthesis 00907. 00000 - "missing right parenthesis"
为什么会出现这个错误?在哪里更改代码以使其工作?
感谢您的帮助!
答案 0 :(得分:0)
好吧,您必须从UPDATE语句中删除ORDER BY
。
我没有你的表结构和数据,试试
MERGE INTO schema_1.table_1 table1
USING (SELECT *
FROM schema_2.table_2 table2
LEFT JOIN
schema_2.view_1 view1
ON table2.column_4 = view1.column_1) t2
ON (table1.column_2 = t2.column_5)
WHEN MATCHED
THEN
UPDATE SET
table1.column_3 = t2.column_6
WHERE table1.column_2 IN
(SELECT table1.column_2
FROM schema_1.table_1 table1,
schema1.table_3 table3,
schema1.table_4 table4,
schema1.table_5 table5,
schema1.table_6 table6,
schema1.table_7 table7
WHERE table4.column_7 = table3.column_8
AND table5.column_9 = table4.column_10
AND table5.column_11 = table1.column_12
AND table4.column_13 = table7.column_14
AND table7.column_15 = table6.column_16
AND table6.column_17 = 'DOL'
AND table4.column_18 = 1
AND table1.column_2 IS NOT NULL
AND table1.column_3 IS NULL)