SQL*Plus can be used to generate reports from your queries. There are a variety of environment commands that adjust the appearance of your output. The following table describes some of these environment commands.
SQL*Plus Environment command
Description
COL[UMN] columnname [expression]
Specify attributes for the column. Expression can be one or more of these choices:
FORMAT [An | 999] - set the width of column
HEADING text - text in column heading
JUSTIFY [LEFT | RIGHT | CENTER] NOPRINT NEWLINE - go to new line before printing column
SET attribute
Adjust environment settings. Attributes listed below are the more popular ones. The first option is the default setting. There are many more attributes.
>ECHO [OFF|ON]
Repeat a command in a file before executing it.
FEED[BACK] [6|n|OFF|ON]
Report how many rows you want returned.
HEA[DING] [OFF|ON]
Turn on and off all column headings.
LIN[ESIZE] [80|n]
Adjust number of characters per line.
PAGES[IZE] [24|n]
Adjust number of lines per page.
TERM[OUT] [OFF|ON]
Turn on and off output display.
TIMI[NG] [OFF|ON]
Turn on and off performance display.
VER[IFY] [OFF|ON]
Turn on and off variable substitution display.
SHOW [ALL | attribute ]
Show the setting(s) for all attributes or for the specified attribute.
Review the followingseries of images to see how easy it is to change a query into a report good enough to print.
Editing Scripts in SQL*Plus Command-Line
You can use a number of SQL*Plus commands to edit the SQL command or PL/SQL block currently stored in the buffer.
The SQL*Plus CHANGE command enables you to edit the current line. Various actions determine which line is the current line:
LIST a given line to make it the current line.
When you LIST or RUN the command in the buffer, the last line of the command becomes the current line. (Note, that using the slash (/) command to run the command in the buffer does not affect the current line.)
If you get an error, the error line automatically becomes the current line.
Using SQL*Plus commands to adjust Column and Page Settings
The next lesson continues with more SQL*Plus environment commands that help create reports.
SQL*Plus environment commands to Adjust Column Page Settings.
Your solution should have followed these steps:
You executed the query for your report by typing / at the SQL> prompt and pressing Enter.
You created a file with this query in it so that you could add some SQL*Plus commands to it. You wrote the query to a file named CUST_BUY.sql by typing SAVE CUST_BUY at the SQL> prompt and pressing Enter.
You made some changes to the file you created by starting up a text editor. You typed EDIT CUST_BUY at the SQL> prompt and pressed Enter.
In the first line of the file, you typed COLUMN SALES_DATE HEADING "SALES DT" to change the heading of the first column in the Select clause to SALES DT. You then pressed Enter.
You changed the column width to 15 characters and changed the column heading to NAME by typing COLUMN LASTNAME FORMAT A15 HEADING "NAME" in the next line. You then pressed Enter.
You changed the column width to two numeric characters and changed the column heading to # ITEMS by typing COLUMN PROD_COUNT FORMAT 99 HEADING "# ITEMS" in the next line. You then pressed Enter.
You typed COLUMN TOTAL_SALE FORMAT 9999.99 HEADING "PMT" at the first blank line in the file to change the column width to four numbers to the left and two numbers to the right of the decimal point, and to change the column heading to PMT. You then pressed Enter.
You changed the number of lines per page to 22 by typing SET PAGESIZE 22 at the first blank line in the file and then pressing Enter.
You changed the number of characters per line to 45 by typing SET LINESIZE 45 in the next blank line and then clicking the X in top right corner to close the text editor.
You saved your changes by clicking the Yes button. /li>
You tested your query and the SQL*Plus environment settings you made by typing START CUST_BUY at the SQL> prompt and pressing Enter.
You viewed the query results and then completed the exercise by clicking the Exit button.