如何通过SAS SQL-pass-through工具显示Oracle SQL Script输出?

时间:2015-02-04 16:39:02

标签: sql oracle sas

背景:

当我通过Oracle SQL Developer提交SQL MERGE查询时(例如,将事务表BUF_TRAN合并到基表BUF_BASE中),它返回有用的脚本输出(在脚本中)输出窗口),例如2 rows merged0 rows merged等。它使我能够快速了解​​更新的数据大小。

但是,当我通过SAS SQL-pass-through工具提交相同的SQL查询时,它会忽略返回脚本输出。

问题:

有没有办法让SAS编写oracle查询脚本输出作为SAS SQL-pass-through步骤的一部分?

示例代码(用于模拟):

一次性:在Oracle中创建表BUF_BASEBUF_TRAN。表格看起来像这样......

BUF_BASE

enter image description here

BUF_TRAN

enter image description here

在Oracle SQL Developer中运行以下PL / SQL将在Oracle中创建这些表,并填充数据。

-- One-off: Create a base table and populate 1 row to it
DROP TABLE BUF_BASE;
CREATE TABLE BUF_BASE
  (
    NODE             VARCHAR2(64) NOT NULL,
    DATE_STAMP       VARCHAR2(10) NOT NULL,
    PCT_USAGE        VARCHAR2(12) NOT NULL,
    JOBRUN_DATE_TIME VARCHAR2(19) NOT NULL,
    CONSTRAINT node_date_pk PRIMARY KEY (NODE, DATE_STAMP)
  ) ;
INSERT
INTO BUF_BASE
  (
    NODE,
    DATE_STAMP,
    PCT_USAGE,
    JOBRUN_DATE_TIME
  )
  VALUES
  (
    'A',
    '2015-01-01',
    '5',
    '2015-01-02T00:00:00'
  ) ;

-- One-off: Create the transaction table that has some rows to begin with.
DROP TABLE BUF_TRAN;
CREATE TABLE BUF_TRAN
  (
    NODE             VARCHAR2(64) NOT NULL,
    DATE_STAMP       VARCHAR2(10) NOT NULL,
    PCT_USAGE        VARCHAR2(12) NOT NULL,
    JOBRUN_DATE_TIME VARCHAR2(19) NOT NULL
  ) ;
INSERT
INTO BUF_TRAN
  (
    NODE,
    DATE_STAMP,
    PCT_USAGE,
    JOBRUN_DATE_TIME
  )
  VALUES
  (
    'A',
    '2015-01-01',
    '10',
    '2015-01-15T00:00:00'
  ) ;
INSERT
INTO BUF_TRAN
  (
    NODE,
    DATE_STAMP,
    PCT_USAGE,
    JOBRUN_DATE_TIME
  )
  VALUES
  (
    'A',
    '2015-01-02',
    '20',
    '2015-01-15T00:00:00'
  ) ;
commit;

然后在Oracle SQL Developer中运行以下MERGE查询,以使用BUF_BASE更新BUF_TRAN

-- Merge transaction data into the base table
MERGE INTO BUF_BASE a USING BUF_TRAN b ON (a.NODE = b.NODE AND a.DATE_STAMP = b.DATE_STAMP)
WHEN MATCHED THEN
  UPDATE
  SET a.PCT_USAGE          = b.PCT_USAGE,
    a.JOBRUN_DATE_TIME     = b.JOBRUN_DATE_TIME
  WHERE b.JOBRUN_DATE_TIME > a.JOBRUN_DATE_TIME WHEN NOT MATCHED THEN
  INSERT
    (
      NODE,
      DATE_STAMP,
      PCT_USAGE,
      JOBRUN_DATE_TIME
    )
    VALUES
    (
      b.NODE,
      b.DATE_STAMP,
      b.PCT_USAGE,
      b.JOBRUN_DATE_TIME
    )
;
commit;

通过运行上述MERGE查询,“脚本输出”窗口显示:

2 rows merged.
committed.

再次运行MERGE查询,然后会说

0 rows merged.
committed.

现在,通过SQL-pass-through工具在SAS中运行相同的MERGE查询。

proc sql;
  connect to oracle (user=&BcoUser. password=&BcoPassword. path=&BcoPath.);
  execute (

MERGE INTO BUF_BASE a USING BUF_TRAN b ON (a.NODE = b.NODE AND a.DATE_STAMP = b.DATE_STAMP)
WHEN MATCHED THEN
  UPDATE
  SET a.PCT_USAGE          = b.PCT_USAGE,
    a.JOBRUN_DATE_TIME     = b.JOBRUN_DATE_TIME
  WHERE b.JOBRUN_DATE_TIME > a.JOBRUN_DATE_TIME WHEN NOT MATCHED THEN
  INSERT
    (
      NODE,
      DATE_STAMP,
      PCT_USAGE,
      JOBRUN_DATE_TIME
    )
    VALUES
    (
      b.NODE,
      b.DATE_STAMP,
      b.PCT_USAGE,
      b.JOBRUN_DATE_TIME
    )

  ) by oracle;

  %put &SYSDBMSG.;
  %put &SYSDBRC.;

  execute (
     commit
  ) by oracle;

  %put &SYSDBMSG.;
  %put &SYSDBRC.;

  disconnect from oracle;
quit;

SAS日志文件只返回作业运行时间(错误消息0)。但它并没有告诉我合并了多少行。

问题:

有没有办法让SAS编写oracle查询脚本输出作为SAS SQL-pass-through步骤的一部分? e.g。

0 rows merged.
committed.

0 个答案:

没有答案