СУБД Oracle / Лекции / Лек_ORAC / L89 / ch7_xref
.docrem
rem CH7_XREF.SQL - Создание многотабличного матричного
rem отчета с перекрестными ссылками
rem Oracle9i by Example
rem by Dan Hotka
rem Que Publications June 2001
rem All Rights Reserved
rem
rem Запуск: @d:\ch7_xref.sql дата_отчёта
define RPT_DATE = &1 -- Ввод даты отчёта
-- Запрещаем доп.выводы и прочие установки
SET FEEDBACK OFF
SET VERIFY OFF
SET TERMOUT OFF
SET ECHO OFF
SET LINESIZE 61
-- Задаём форматы столбцов
COLUMN CLERK format 999999 heading 'Clerk'
COLUMN MANAGER format 999999 heading 'Manager'
COLUMN SALESMAN format 999999 heading 'Salesman'
COLUMN ANALYST format 999999 heading 'Analyst'
COLUMN PRESIDENT format 999999 heading 'President'
COLUMN TOTALS format 999999 heading 'Totals'
-- Задаём оформление итогов
BREAK ON REPORT SKIP 2
COMPUTE SUM OF CLERK on report
COMPUTE SUM OF ANALYST on report
COMPUTE SUM OF MANAGER on report
COMPUTE SUM OF SALESMAN on report
COMPUTE SUM OF PRESIDENT on report
COMPUTE SUM OF TOTALS on report
-- Задаём двухстрочное оформление заголовка
TTITLE left '&RPT_DATE' ce 'Salary Cross-Tabular' RIGHT 'Page: '-
format 999 SQL.PNO skip CENTER 'by Job/Department' skip 2
SPOOL D:\CH3_XREF.TXT
SELECT deptno,
SUM(DECODE(SUBSTR(job,1,1),'C',sal,0)) CLERK,
SUM(DECODE(SUBSTR(job,1,1),'A',sal,0)) ANALYST,
SUM(DECODE(SUBSTR(job,1,1),'M',sal,0)) MANAGER,
SUM(DECODE(SUBSTR(job,1,1),'S',sal,0)) SALESMAN,
SUM(DECODE(SUBSTR(job,1,1),'P',sal,0)) PRESIDENT,
SUM(sal) TOTALS
FROM emp
GROUP BY deptno
/
SPOOL OFF
EXIT
11/05/2003 Salary Cross-Tabular Page: 1
by Job/Department
DEPTNO Clerk Analyst Manager Salesman President Totals
--------- ------- ------- ------- -------- --------- -------
10 1300 0 2450 0 5000 8750
20 1900 6000 2975 0 0 10875
30 950 0 2850 5600 0 9400
------- ------- ------- -------- --------- -------
sum 4150 6000 8275 5600 5000 29025