【问题标题】:How to do DBMS_OUTPUT print within oracle merge into?如何在 oracle 中合并 DBMS_OUTPUT 打印?
【发布时间】:2018-05-29 07:18:28
【问题描述】:

我有这个

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 - “缺少关键字”

这是一种打印列值的方法吗?

【问题讨论】:

    标签: oracle oracle11g


    【解决方案1】:

    MERGE INTO 是 SQL 语句,DBMS_OUTPUT.PUT_LINE 是 PL/SQL 过程。您试图将这两者结合在一个语句中,这是不可能的。

    仅当您要执行INSERTUPDATE 时才有效。

    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 joinCASE

    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;
    

    【讨论】:

      猜你喜欢
      • 2017-02-28
      • 2017-06-15
      • 2020-05-28
      • 2020-01-29
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多