Professional Documents
Culture Documents
SETTING FEEDBACK
SQLPLUS tells you how many rows it found in a table. This is called feedback.
You can turn it off or on. The default value is 6 rows.
It has a counterpart named SHOW to allow you to see the instructions you've
typed, e.g.
Show feedback
Set numwidth 10 will set the numberwidth for number columns to 10.
Columns with more than 10 numbers will not display correctly.
REPORT COMMANDS
Reports are produced by storing commands to a file that can be executed by
using the SQLPLUS START command. You may use whatever editor you
prefer to create the report file.
REMARK
This command can be shortened to REM. SQLPLUS ignores anything on a
line that begins with REM to allow you to document your program file.
SET HEADSEP
This is a Heading Separator command to tell SQLPLUS how you will indicate
where you wish to break a page or column heading that is more than one line.
The default is the vertical bar (|), but if your keyboard does not have this, use
this command to select another character like the exclamation point.
Set headsep !
The BTITLE command is for the bottom of each page and centers the output
on each page.
COLUMN
This command allows you to change the heading and format of a column that
is in a SELECT statement. This example produces a two-line heading for the
column named ITEM, and the following command sets ITEM to alpha, 18
columns of output, with all characters after 18 being word wrapped to the next
line:
BREAK ON
To produce grouping of items as in a control break report, use the BREAK ON
command, in conjunction with the ORDER BY option in the SELECT
command.
SQLPLUS will examine each row and track the value in Item. When the value
for Item changes, SQLPLUS will skip two lines. Also the value for Item is
printed on the first line of its section to eliminate duplicate printing of each of
these items for every row in each section.
If you want a grand total for the report, use the command:
If you just use BREAK ON report, then the second BREAK ON command will
override the first one.
COMPUTE SUM
This calculates totals for each section of the report. It will always total for the
field specified in the BREAK ON command. This will compute the total sum of
the values of Ext for each Item. This command must be used in conjunction
with the BREAK ON command. Treat them as a single unit of two related
commands.
SET PAGESIZE sets the total number of lines of output on a page including
all headings and blank line prints. You usually use 66 lines for output, but
sometimes 60 works better for some printers.
SET NEWPAGE actually sets blank lines that print before the top line
SPOOL
Spooling a file is writing the file to a print queue To name the output file for
your report, use the SPOOL command. We usually use a default filename
extension of lst (stands for listing).
Spool myoutputfile.lst
/* */ REMARKS
Use this option to embed comments in an SQL statement. Everything within
the symbols is treated as a remark.
COMMAND LINE EDITOR
SQLPLUS has a scratchpad buffer where is stores commands. It only stores
the most recent command. Consider the example command:
You can LIST the contents of the editor to correct the typing error.
SQL list
1 select Featuer, Section, Page
2 from NEWSPAPER
3* where Section = 'F'
SQL list 1
1* select Featuer, Section, Page
To change the value, use the Change command to type the original spelling
and the new spelling divided by delimiters (here we use the / symbol to delimit
the text, but you could also use any other special character like the $ symbol).
I also abbreviated Change with the letter C.
SQL c/Featuer/Feature/
1* select Feature, Section, Page
SQL /
FEATURE S PAGE
--------------- - ----------
Births F 7
Classified F 8
Obituaries F 6
Doctor Is In F 6
There are other options to use with the buffer editor. I tend to put my code in
an ASCII file and edit the file directly as opposed to using the buffer editor.
I also define the editor to use for my files to be the vi editor. Put all of these
commands in your login.sql file.
You can temporarily host out to the operating system with the HOST
command. This is useful to copy files, etc. You execute the EXIT command to
return to SQLPLUS.
START
This command is used to execute an SQL report file. Use the filename
extension of SQL for your program files. Example:
Start myreportfile.sql
Column Item will display the instructions about the column named Item
Ttitle will display instructions about the TTITLE command value
Btitle will display instructions about the BTITLE command value
Compute will display information about the COMPUTE command value
USING SHOW
Use the SHOW command to display information about values that were set
with the SET command.
Show headsep
Show linesize
Show pagesize
Show newpage
EXAMPLE
SPOOL TEMP
CLEAR COLUMNS
CLEAR BREAKS
CLEAR COMPUTES
SET PAGESIZE 24
SET NEWPAGE 0
SET LINESIZE 70
SPOOL OFF
If you do not want to see the output on your screen, you can also add SET TERMOUT OFF to
the beginning of the file and SET TERMOUT ON to the end of the file. Save and close the file in
your text editor (you will automatically return to SQL*Plus). Now, run the script EMPRPT:
@EMPRPT
SQL*Plus displays the output on your screen (unless you set TERMOUT to OFF), and spools it
to the file TEMP:
A C M E W I D G E T
80 Russell $14,000
Partners $13,500
********** --------------
sum $27,500
90 King $24,000
Kochhar $17,000
De Haan $17,000
********** --------------
sum $58,000
--------------
sum $98,500
COMPANY CONFIDENTIAL
6 rows selected.