Beruflich Dokumente
Kultur Dokumente
Report Development
SELECT 'Hello -
World!!!'
FROM DUAL;
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.1
/* Practice 1: Modify the above command to produce the following results */
MESSAGE
--------------
Hello World!!!
Oracle's World!
--------------------
use quote in Heading
run a:\format.sql
spool a:\command_file
spool off
/
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.2
Formatting Text Reports
SQL*Plus allows you to define:
-- column heading
-- display formats for each column
-- page headers and footers
-- page and line breaks
-- summary calculation such as total and subtotal
Column Heading
Specify column heading using the HEADING clause of the COLUMN command
Multi-line Heading
To specify multi-line heading use the vertical bar '|'character
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.3
...
25 rows selected.
Column Formats
∗You can specify display formats with the FORMAT clause of the COLUMN command.
∗The later section "SQL*Plus Format Elements" shows how to format different types of data.
Page Width and Length
Page Width and Length
∗Page width is controlled by SET LINESIZE command. The default length is 80 characters.
SET LINESIZE 60
SELECT *
FROM employee;
-- The above change will cause line wrapping. Let change it back to 80.
Page Length
Page length is controlled by the SET PAGESIZE command.
∗Specifies the number of lines per page of output.
∗The default is set print 24 lines.
∗The printed lines includes the page header and footer lines.
∗Setting PAGESIZE to zero has special meaning in SQL*PLUS.
∗A PAGESIZE of zero will not print page header and footer, and column headings.
Page Headers
Defining a TOP Title (TTITLE) through an example.
∗In the first line: the "company name" will be left justified, the word "Current" will be
centered, the page number will be right justified.
∗In the second Line: the word "Employee Listing will be centered, the final skip clause (SKIP
4) provides three blank lines between the page title and the column headers.
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.4
My Company CURRENT Page 1
Employee Listing
SET LINESIZE 85
TTITLE LEFT "My Company" CENTER "CURRENT" -
LEFT "Report Date: " report_date SKIP 1 -
CENTER "Employee Listing" SKIP 3
BTITLE LEFT " Report is developed by Cyrus Azarbod" -
RIGHT "Page" FORMAT 999 SQL.PNO
COLUMN lname HEADING "Last Name" JUSTIFY CENTER
COLUMN fname HEADING "First Name" JUSTIFY CENTER
CLEAR COLUMN
TTITLE OFF
BTITLE OFF
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.5
1011 JENNIFER DAVIS 11-NOV-72 100 7011
1012 MARIA MILLER 12-DEC-69 100 7012
CURDATE
----------
28-Feb-003
∗After executing the commands shown in the above, the date will be in a user variable
named "report_date".
CURDATE
----------
28-Feb-003
CLEAR COLUMN
TTITLE OFF
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.6
BTITLE OFF
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.7
My Company CURRENT Report Date: 28-Feb-003
Employee Listing
Page Breaks
SET NEWPAGE controls SQL*Plus's action when a page break occurs.
By default, SQL*Plus prints one blank line between each page of output.
SET NEWPAGE 10
SQL*Plus can print one form-feed character between pages if it SETS to zero
SET NEWPAGE 0
Both form-feed character and blank line can be eliminated by setting it to NONE. This
option available in newer SQL*Plus version!
SET NEWPAGE NONE
Report Breaks
Break command can be Used to eliminate repetitive column values.
SQL*Plus prints the value of the column only when it changes.
It is important to sort the query results on the same column.
BREAK ON OWNER
SELECT owner, table_name
FROM all_tables
ORDER BY owner, table_name;
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.8
Without BREAK command
SELECT owner, table_name
FROM all_tables
ORDER BY owner, table_name;
OWNER TABLE_NAME
------------------------------ ----------------
MLS SPONSER
MLS TEAM
MLS TEAMPLAYER
MLS TEAMSPONSER
MLS TEAMSTATUS
MTSSYS MTS_PROXY_INFO
OES BRANCH
OES CUSTOMER
OES EMPLOYEE
OES ORDERLINE
OES ORDERS
OES PRODUCT
OES RETURNPROD
PROP BRANCH
....
OWNER TABLE_NAME
------------------------------ ------------------
...
MLS ADDRESS
DRAFT
EMPLOYEE
EMPPOSITION
GAMESCHEDULE
GAMETYPE
OES BRANCH
CUSTOMER
EMPLOYEE
ORDERLINE
ORDERS
PRODUCT
RETURNPROD
PROP BRANCH
CLIENT
...
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.9
Break command to skip line(s) whenever a value changes
BREAK ON owner SKIP 1
SELECT owner, table_name
FROM all_tables
ORDER BY owner, table_name;
OWNER TABLE_NAME
------------------------------ ------------------
...
MLS ADDRESS
DRAFT
EMPLOYEE
EMPPOSITION
GAMESCHEDULE
GAMETYPE
OES BRANCH
CUSTOMER
EMPLOYEE
ORDERLINE
ORDERS
PRODUCT
RETURNPROD
PROP BRANCH
CLIENT
...
OWNER TABLE_NAME
------------------------------ ------------------------------
...
MLS ADDRESS
DRAFT
EMPLOYEE
OWNER TABLE_NAME
------------------------------ ------------------------------
OES BRANCH
CUSTOMER
EMPLOYEE
ORDERLINE
ORDERS
PRODUCT
RETURNPROD
OWNER TABLE_NAME
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.10
------------------------------ ------------------------------
PROP BRANCH
CLIENT
LEASE
...
MLS ADDRESS
DRAFT
EMPLOYEE
PROP BRANCH
CLIENT
LEASE
BREAK ON owner
COMPUTE COUNT OF table_name ON owner SKIP 1
col owner FORMAT A15
col table_name FORMAT A15
SELECT owner, table_name
FROM all_tables
ORDER BY owner, table_name;
CLEAR BREAK
CLEAR COMPUTE
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.11
The COMPUTE command- example
OWNER TABLE_NAME
--------------- ---------------
...
MLS SPONSER
TEAM
TEAMPLAYER
TEAMSPONSER
TEAMSTATUS
*************** ---------------
count 13
OES BRANCH
CUSTOMER
EMPLOYEE
ORDERLINE
ORDERS
PRODUCT
RETURNPROD
*************** ---------------
count 7
...
∗control data format using what is called format specification. Format specification is string
of
∗characters that tell SQL*Plus exactly how to format a number, date, or text string when it
is displayed.
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.12
SQL*Plus FORMAT ELEMENTS:
Date Format Elements
Date Format Examples:
Format Result
dd-mon-yyyy 13-dec-2002
dd-Mon-yyyy 13-Dec-2002
DD-MON-YYYY 13-DEC-2002
Month DD, YYYY December 13, 2002
mm/dd/yyyy 12/13/2002
Day Friday
A
------------------
An apple a day
keeps the doctor
away.
New Date
-----------------------
05-Jan-2003 10:05:19 PM
New Date
-----------
05-Jan-2003
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.13
Sample Report 1
Develop a report to list employee name, and commission.
This report should have date and page no. at bottom of each page.
CLEAR COLUMN
CLEAR BREAK
CLEAR COMPUTE
TTITLE OFF
BTITLE OFF
SET linesize 70
COLUMN name head 'Employee |Name' for a35
COLUMN commission head 'Total Commission' for $99,999.99
COLUMN sysdate noprint old_val day
TTITLE center "Employee First and Last Names"
BTITLE day center sql.pno
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.14
Sample Report 2
∗Develop a formatted report to list every branch and employee assigned to that branch
∗This list should include last name, and commission.
∗This report should have date and page number at bottom of every page.
CLEAR COLUMN
CLEAR BREAK
CLEAR COMPUTE
TTITLE OFF
BTITLE OFF
SET PAGESIZE 10
COLUMN city format a13
COLUMN city noprint new_val branch
COLUMN sysdate noprint old_val day
TTITLE LEFT "List of Employee for branch:" center branch
BTITLEe day CENTER sql.pno skip 1
BREAK ON city page
COLUMN 'First Name' format a14
COLUMN 'Last Name' format a14
SELECT sysdate, b.city, lname "Last Name", fname "First Name", commission
FROM branch b, employee e
where b.branch_no = e.branch_no;
SET PAGESIZE 24
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.15
Sample Report 3
Sample Report 3
List of Employee
************* -----------
Total Branch $160.00
28-FEB-03 9
...
25 rows selected.
AUTO[COMMIT]
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.16
-- Determines whether Oracle will commit changes immediately or
-- after a specified number of commands
SET AUTOCOMMIT
BLOCKTERMINATOR
-- Determines the symbol used to denote the end of a PL/SQL block
COLSEP {TEXT| }
-- Determine the values to be printed between columns.
DEF[INE]
-- Defines the character is used to indicate a substitution variable.
-- The default is '&'.
EDITF[ILE]
Sets the default filename that the EDIT command uses.
ESCAPE
The escape symbol may be changed from the default backslash '\'.
OFF disables this setting.
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.17
-- The default is ON
SET HEADING OFF
HEADS[EP] - LIN[ESIZE]
HEADS[EP] {OFF | ON}
-- Changes the default heading separator '|' to another symbol.
LIN[ESIZE] {n}
-- Page width is controlled by LINESIZE.
-- Default line size is set to 80
SET LINESIZE 50
HEADS[EP] - LIN[ESIZE]
NEWP[AGE]
-- Specifies the number of blank lines to be printed between the bottom -
-- of one page and the top of the next page
-- A value of 0 sends a form feed at the top of each page
NULL
-- Enables you to substitute text for a null value when they are encountered
PAGESIZE
PAGESIZE {n}
∗Specifies the number of lines per page of output.
∗The default is set print 24 lines.
∗The printed lines includes the page header and footer lines.
∗Setting PAGESIZE to zero has special meaning in SQL*PLUS.
∗A PAGESIZE of zero will not print page header and footer, and col headings.
∗When using SET MARKUP HTML ON to generate HTML output, PAGESIZE controls -
∗the number of HTML table rows that display before column heading are repeated.
set PAGESIZE 12
_________________________________________________________________________
© Cyrus Azarbod Oracle SQL *Plus 2.5.18