我有这个
set serveroutput on size 30000
MERGE INTO ADV_TEST_INSTITUTION to_t
USING INSTITUTION from_t
ON (to_t.CALLISTA_INSTITUTION_CD = from_t.INSTITUTION_CD)
WHEN NOT MATCHED THEN
DBMS_OUTPUT.PUT_LINE('not match: ' || from_t.name)
WHEN MATCHED THEN
DBMS_OUTPUT.PUT_LINE('match: ' || from_t.name);
错误:
错误报告 - SQL错误:ORA-00905:缺少关键字 00905. 00000 - "缺少关键字"
是否可以打印列的值?
答案 0 :(得分:3)
MERGE INTO
是一个SQL语句,DBMS_OUTPUT.PUT_LINE
是一个PL / SQL过程。您试图将这两者合并为一个语句,这是不可能的。
仅当您要执行INSERT
或UPDATE
时才有效。
MERGE INTO ADV_TEST_INSTITUTION to_t
USING INSTITUTION from_t
ON (to_t.CALLISTA_INSTITUTION_CD = from_t.INSTITUTION_CD)
WHEN NOT MATCHED THEN
INSERT ( col1,col2,col3) VALUES ( fromt.col1,from_t.col2,from_t.col3)
WHEN MATCHED THEN
UPDATE SET to_t.col1 = from_t.col1 , to_t.col12 = from_t.col2;
如果你的目的只是比较两个表中的记录,而不是执行任何DML,
您可以像这样使用LEFT join
和CASE
。
SELECT CASE
WHEN to_t.CALLISTA_INSTITUTION_CD IS NULL
THEN
'not match: ' || from_t.name
ELSE
'match: ' || from_t.name
END
AS match_nomatch
FROM INSTITUTION from_t
LEFT JOIN ADV_TEST_INSTITUTION to_t
ON to_t.CALLISTA_INSTITUTION_CD = from_t.INSTITUTION_CD;