SQL * Plus自定义摘要报告

问题描述 投票:0回答:1

我需要生成如下所示的摘要报告:

enter image description here

我的问题是,

  1. 我不知道如何在此自定义报告中填写计数数据。
  2. 我不知道如何将其放在文本文档中的上述表格视图中。它不是HTML。

到目前为止,我只知道如何在没有表视图的情况下执行第一行和第一列。

这是我的密码。

SET HEADING OFF;
SET LINESIZE 200;
SET SPACE 0; 
SET ECHO OFF;
SET FEEDBACK OFF;
SET VERIFY OFF;
SET MARKUP HTML OFF SPOOL OFF;
SET TERMOUT OFF; --Do not show output to the screen.
SET NEWPAGE NONE; --Remove the first blank line at the top of the page and between queries.

TTITLE LEFT "REPORT NAME" RIGHT "PAGE : " SQL.PNO SKIP 1 -
LEFT        "--------------------------------" RIGHT "DATE : " _DATE SKIP 1 -
LEFT "A) TOTAL RECORDS " RIGHT total_records; -- Cannot output variable in the title.
LEFT "B) MATCHED RECORDS " RIGHT matched_records; -- Cannot output variable in the title.
LEFT "C) UNMATCHED RECORDS " RIGHT matched_records; -- Cannot output variable in the title.
BTITLE LEFT "E N D";

total_records是一条插入语句。

SELECT COUNT(*) INTO total_records FROM TABLE;

我还没有完成匹配的记录和不匹配的记录。但我能想到的唯一方法

  1. 选择一个用于游标的语句。
  2. 进入光标。
  3. 匹配时增加匹配数。
  4. 一次循环结束。不匹配的计数=总计数-匹配的计数。

我认为这不是最有效的方法。但是,如果您有更好的方法,请告诉我。

oracle report sqlplus spool
1个回答
0
投票

这样的东西响吗?示例基于Scott的示例架构:

SQL> select 'Total records' name, count(*) cnt
  2    from emp
  3  union all
  4  select 'Matched count', sum(case when deptno = 10 then 1 else 0 end)
  5    from emp
  6  union all
  7  select 'Unmatched count', sum(case when deptno = 10 then 0 else 1 end)
  8    from emp;

NAME                   CNT
--------------- ----------
Total records           14
Matched count            3
Unmatched count         11

SQL>
© www.soinside.com 2019 - 2024. All rights reserved.