The SET Command

SQL*Plus contains a large number of internal variables that control various aspects of the way the product operates. The SET command is used to change these settings to suit your preferences. The number of settings is quite large, so for convenience I’ve divided them into the following categories:

  • Report output and format settings

  • Feedback settings

  • Input settings

  • Operational settings

  • Substitution variable settings

  • Large object settings

  • Tuning and timing settings

  • Database administration settings

  • Miscellaneous settings

The following sections describe the settings available in each of these categories.

Report Output and Format Settings

The largest group of SQL*Plus settings exists to control the way data is formatted, displayed, and output for a report. These settings control such things as the number of lines on a page, the line length, whether or not tab characters are used to format the output, and so forth. The following list briefly describes each of these settings:

COLSEP

Controls the text used to separate columns of data.

EMBEDDED

Turns the embedded report feature on or off.

HEADSEP

Controls the character used to mark a line break in a column heading.

HEADING

Controls whether or not column headings are displayed when selecting data.

LINESIZE

Specifies the maximum line width.

MAXDATA

The maximum row length SQL*Plus can handle.

NEWPAGE

Controls what SQL*Plus prints when advancing to a new page.

NULL

Contains the text SQL*Plus displays for any null values returned by a query.

NUMFORMAT

The default display format for numbers.

NUMWIDTH

The default column width used for numeric columns.

PAGESIZE

The number of printable lines on a page.

RECSEP

Controls whether or not a record separator is printed between rows of output.

RECSEPCHAR

The record separator character.

SHIFTINOUT

Controls the display of shift characters on IBM 3270 terminals.

SPACE

Specifies the number of spaces printed between columns.

TAB

Controls whether or not SQL*Plus uses tab characters to format whitespace.

TRIMOUT

Controls whether or not trailing spaces are displayed.

TRIMSPOOL

Controls whether or not trailing spaces are written to a spool file.

TRUNCATE

Controls whether or not SQL*Plus truncates long lines.

UNDERLINE

The character used to underline column headings.

WRAP

Controls whether or not SQL*Plus wraps or truncates long lines.

The following sections provide the syntax, and usage examples, for each of these settings.

SET COLSEP

Use SET COLSEP to change the text that prints between columns of data.

SET COLSEP column_separator

where:

SET COLSEP

Is the command, which may not be abbreviated.

column_separator

Is the text you want to print between columns. You should enclose this text in quotes if it contains any spaces or punctuation.

The default column separator is a single space. The following example shows how you can change it to a comma:

SQL> SET COLSEP ","
SQL> SELECT 'One' one,
  2         'Two' two
  3    FROM dual;

ONE,TWO
---,---
One,Two

Like a space, the comma in this example is a single character. You aren’t limited to one character, though. You could just as easily change the column separator to a string of several characters.

SET EMBEDDED

The SET EMBEDDED command controls the printing of embedded reports. The default setting is OFF, which causes the results of each new query to print on a new page, and also causes page numbering to start over each time a SELECT statement is executed.

SET EMB[EDDED] {ON|OFF}
SET EMB[EDDED]

Is the command, which may be abbreviated to SET EMB.

ON

Turns the embedded report feature on. Executing a SELECT statement will not force a page break, nor will it reset the page number.

OFF

Turns the embedded report feature off. Executing a SELECT statement will force a page break, and the page number will be reset to 1.

An embedded report is one that prints as if it were the continuation of a previous report. The following example shows the results of executing two SELECT statements with the default setting. A page title has been created in order to show the effect on page numbering:

SQL> SET EMBEDDED OFF
SQL> SET PAGESIZE 24
SQL> SET NEWPAGE 1
SQL> TTITLE LEFT "Example of SET EMBEDDED, Page " SQL.PNO
SQL> SELECT * FROM dual;

Example of SET EMBEDDED, Page         1
D
-
X

SQL> SELECT * FROM dual;

Example of SET EMBEDDED, Page         1
D
-
X

Notice that the second SELECT statement generated a page break — you can see that the page title printed again. You can also see, by looking at the titles, that page numbering for each query began with page 1. Now take a look at the same example, but with SET EMBEDDED ON:

SQL> SET EMBEDDED OFF
SQL> SET PAGESIZE 24
SQL> SET NEWPAGE 1
SQL> TTITLE LEFT "Example of SET EMBEDDED, Page " SQL.PNO
SQL> SELECT * FROM dual;

Example of SET EMBEDDED, Page         1
D
-
X

SQL> SET EMBEDDED ON
SQL> SELECT * FROM dual;
D
-
X

This time, the second SELECT statement did not generate a page break. The second report began printing on the same page on which the first report ended.

Tip

Be sure to execute the first query of a report with SET EMBEDDED OFF. Otherwise, you may find that SQL*Plus continues the page numbering from a query executed earlier during the session.

If you have defined a page footer (BTITLE) for your report, then a page break will occur at the end of the report, regardless of the EMBEDDED setting. There are a couple of reasons for this behavior. One is that SQL*Plus processes commands one line at a time. SQL*Plus doesn’t know about the second SELECT statement until after it is completely finished printing the results of the first one. If a page footer is defined, SQL*Plus must print it, because it has no way of knowing whether or not another SELECT statement is coming. In order for a page footer to print, SQL*Plus must advance printing to the bottom of the page. After the footer has printed, any new data must begin on a new page. The embedded setting, however, still controls whether or not the page number is reset.

SET HEADSEP

Use the SET HEADSEP command when you want to change the character used when defining a two-line column heading:

SET HEADS[EP] heading_separator

where:

SET HEADS[EP]

Is the command, which may be abbreviated to SET HEADS.

heading_separator

Is the new heading separator character, which may be used in subsequent COLUMN commands to mark line breaks in multiline column headings.

Normally, this character is a vertical bar, and marks the place in a column’s heading where you want a line break to occur. The following example shows a two-line heading being defined:

SQL> COLUMN dummy FORMAT A10 HEADING 'Line 1|Line 2'
SQL> SELECT * FROM dual;

Line 1
Line 2
----------
X

As you can see, the vertical bar in the column’s heading text was replaced by a line break when the column heading was printed. If you need to use the vertical bar as part of a column heading, use SET HEADSEP to choose some other character to act as the line break marker.

Tip

The line break in a heading is set when you first define that heading using the COLUMN command. Subsequently changing the heading separator character will not affect column headings you have already defined.

SET HEADING

Use SET HEADING to control whether or not column headings print when you SELECT or PRINT data. The default value for this setting is ON, which allows column headings to print.

SET HEA[DING] [ON|OFF]

where:

SET HEA[DING]

Is the command, which may be abbreviated SET HEA.

ON

Causes column headings to print when you select data.

OFF

Suppresses column headings.

This setting is on by default, so you normally get a column heading whenever you select or print data using either the SELECT command or the PRINT command. For example:

SQL> SELECT * FROM dual;

D
-
X

Change the value to OFF, and your column headings go away. The following example shows this:

SQL> SET HEADING OFF
SQL> SELECT * FROM dual;

X

Tip

Issuing a SET PAGESIZE 0 command will also turn headings off. If you are trying to enable headings, and SET HEADING ON does not appear to be working, then you should check the pagesize as well.

SET LINESIZE

Use SET LINESIZE to control the number of characters SQL*Plus prints on one physical line. The default setting is 80. The maximum width is system-dependent. Under Windows 95, it is 32,767.

SET LIN[ESIZE] line_width

where:

SET LIN[ESIZE]

Is the command, which may be abbreviated to SET LIN.

line_width

Is the new line width, expressed as a number of characters.

The linesize setting is also referenced by SQL*Plus when you define any headers or footers (see TTITLE, BTITLE, REPHEADER, REPFOOTER) that are centered or right-justified.

SET MAXDATA

MAXDATA is an obsolete setting that should no longer be used. SQL*Plus supports it in order to be backward-compatible. MAXDATA controls the maximum row length SQL*Plus can handle.

SET MAXD[ATA] max_row_width

where:

SET MAXD[ATA]

Is the command, which may be abbreviated to SET MAXD.

max_row_width

Is the new setting for the maximum row width you expect to process.

The default setting under Windows 95 is zero, but may vary from one operating system to the next. Under some operating systems, such as Windows 95, this setting seems to have no effect whatsoever on SQL*Plus’s behavior.

SET NEWPAGE

Controls the manner in which the transition from one page to the next is marked. You can have SQL*Plus print a formfeed character at the start of each new page, skip a specific number of lines between pages, or do nothing at all when advancing from one page to another:

SET NEWP[AGE] {lines_to_print|NONE}

where:

SET NEWP[AGE]

Is the command, which may be abbreviated to SET NEWP.

lines_to_print

Tells SQL*Plus to print a specific number of blank lines when a page break occurs. These lines will be printed following the footer (BTITLE) of the page just ending, and prior to the header (TTITLE) of the page just starting. If this value is zero, and only if it is zero, a formfeed character will be printed instead of any blank lines. The default value is 1.

NONE

Causes SQL*Plus to do nothing at all when a page break occurs — no blank lines, no formfeed.

Tip

Use SET NEWPAGE 0 if you want a formfeed printed at the start of each new page.

SET NULL

SET NULL allows you to change the text SQL*Plus prints in a column when the value for that column is null:

SET NULL null_text

where:

SET NULL

Is the command, which may not be abbreviated.

null_text

Is the text you want to print in place of a null value.

The default null text setting is an empty string, which causes null values to print as blanks. The following example shows this, and also shows how the null text may be changed:

SQL> SELECT employee_termination_date 
  2    FROM employee 
  3   WHERE employee_id=101;

EMPLOYEE_
---------

SQL> SET NULL "*NULL*"
SQL> SELECT employee_termination_date 
  2    FROM employee 
  3   WHERE employee_id=101;

EMPLOYEE_
---------
*NULL*

If you use the COLUMN command to format a column, the NULL clause of that command will override this setting, but only for that one column.

SET NUMFORMAT

SET NUMFORMAT allows you to specify the default formatting of numeric values returned from a SELECT statement. Any number format usable with the COLUMN command may also be used with SET NUMFORMAT.

SET NUMF[ORMAT] format_spec

where:

SET NUMF[ORMAT]

Is the command, which may be abbreviated to SET NUMF.

format_spec

Is a numeric format specification, which controls the default manner in which numeric values are displayed. See Appendix B, for a list of formats.

The following example shows the effect of changing the NUMFORMAT setting:

SQL> SELECT 123456.7 FROM dual;

 123456.7
---------
 123456.7

SQL> SET NUMFORMAT $999,999.99
SQL> SELECT 123456.7 FROM dual;

    123456.7
------------
 $123,456.70

The NUMFORMAT setting controls the default display format for numeric values. You can use the COLUMN command to specify display formats on a column-by-column basis, and those take precedence over the NUMFORMAT setting.

SET NUMWIDTH

SET NUMWIDTH controls the default width used when displaying numeric values:

SET NUM[WIDTH] width

where:

SET NUM[WIDTH]

Is the command, which may be abbreviated to SET NUM.

width

Is the default column width used when displaying a numeric value.

The default NUMWIDTH setting is 10. NUMWIDTH is used only when no other settings apply. The following example shows the effect of setting NUMWIDTH to 5:

SQL> SET NUMWIDTH 5
SQL> SELECT 123 FROM dual;

 123
----
 123

A numeric format specified by a COLUMN command or by a SET NUMFORMAT command will override NUMWIDTH. The following example shows this:

SQL> SET NUMWIDTH 5
SQL> SET NUMFORMAT 999,999.99
SQL> SELECT 123 FROM dual;

        123
-----------
     123.00

SQL> SHOW NUMWIDTH
numwidth 5

As you can see, NUMWIDTH is still 5, but that value is ignored because the NUMFORMAT setting takes precedence. A long column title can also cause NUMWIDTH to be ignored, as the following example demonstrates:

SQL> SET NUMWIDTH 5
SQL> SET NUMFORMAT ""
SQL> COLUMN a HEADING "This is a long column title"
SQL> SELECT 123 a FROM dual;

This is a long column title
---------------------------
                        123

As you can see, the column title takes precedence over NUMWIDTH when it comes to determining the width of the column.

SET PAGESIZE

Use SET PAGESIZE to tell SQL*Plus the number of printed lines that will fit on one page of output. You can also use this setting to completely turn off all pagination functions.

SET PAGES[IZE] lines_on_page

where:

SET PAGES[IZE]

Is the command, which may be abbreviated to SET PAGES.

lines_on_page

Is the number of lines you want SQL*Plus to print on one page. This includes detail lines, header lines, and footer lines. The default value for PAGESIZE is 24. For SQL*Plus versions 2.1 and earlier, the default was 14.

The PAGESIZE must be set in conjunction with NEWPAGE. The sum of PAGESIZE and NEWPAGE should equal the number of lines that will physically fit on one page. SQL*Plus will print headers, detail, and footers until PAGESIZE lines have been printed. Then it will print NEWPAGE lines to advance to the next page, where the process starts over again. Your page titles will drift up or down with each new page if these settings don’t match the page’s physical size. The exception to this is when you use SET NEWPAGE 0.

If you use SET NEWPAGE 0 to cause a formfeed to print at the beginning of each page, you should set PAGESIZE to at least one less than the physical number of lines on a page. Failure to do so may result in alternating blank pages in your printed report.

You can completely turn off all pagination by issuing a SET PAGESIZE 0 command. This will eliminate page titles, page footers, column titles, and any blank lines or formfeeds from the NEWPAGE setting.

SET RECSEP

SET RECSEP is used to tell SQL*Plus whether or not to print a record separator between each record displayed as the result of a query. The default setting is not to print anything, except when a long record wraps to a second line. In that case, a blank line is printed as a record separator.

SET RECSEP {WR[APPED]|EA[CH]|OFF}

where:

SET RECSEP

Is the command, which may not be abbreviated.

WR[APPED]

Tells SQL*Plus to print a record separator only when a line wraps. This is the default setting.

EA[CH]

Tells SQL*Plus to print a record separator after each record.

OFF

Tells SQL*Plus not to print any record separators at all.

The default setting is WRAPPED, which is probably a safe choice, because it causes a separator to print only in cases where a break between records may not be obvious — in other words, where each line does not necessarily start a new record. Here is an example of a record separator being printed:

SQL> COLUMN view_name FORMAT A15
SQL> SELECT view_name FROM all_views;
ALL_ALL_TABLES
ALL_ARGUMENTS
ALL_CATALOG
ALL_CLUSTERS
ALL_CLUSTER_HAS
H_EXPRESSIONS

ALL_COLL_TYPES
...

You can see that the record separator, by default a blank line, was printed after the ALL_CLUSTER_HASH_EXPRESSIONS view was listed. This blank line removes any ambiguity about whether H_EXPRESSIONS and ALL_CLUSTER_HAS are two separate views or if a long view name has wrapped to a second line. Setting RECSEP to OFF yields the following results:

SQL> SET RECSEP OFF
SQL> SELECT VIEW_NAME from all_views;
ALL_ALL_TABLES
ALL_ARGUMENTS
ALL_CATALOG
ALL_CLUSTERS
ALL_CLUSTER_HAS
H_EXPRESSIONS
ALL_COLL_TYPES

Do you see six views listed or seven? How would you know?

In addition to controlling whether or not the record separator prints, you can control the character used as well. See the SET RECSEPCHAR command.

SET RECSEPCHAR

Use SET RECSEPCHAR to change the record separator to something other than a line of space characters:

SET RECSEPCHAR separator_char

where:

SET RECSEPCHAR

Is the command, which may not be abbreviated.

separator_char

Is the character you want to use in the record separator line. The default value is a space.

The default record separator is a blank line. The following example shows how you can change it to be a line of asterisks instead:

SQL> SET RECSEPCHAR "*"
SQL> SET RECSEP EACH
SQL> SELECT view_name FROM all_views;
ALL_ALL_TABLES
*****************************************************************************
ALL_ARGUMENTS
*****************************************************************************
ALL_CATALOG
*****************************************************************************

This example uses SET RECSEP EACH to cause a separator to print after each record, so that you will have something to look at. The separator character was set to an asterisk, causing you to get a full line of asterisks between each record. The length of the separator line will match the LINESIZE setting.

SET SHIFTINOUT

The SHIFTINOUT setting controls whether or not shift characters are displayed as part of the output. It is usable only with IBM 3270 terminals and their equivalent, and only when SQL*Plus is displaying data in a shift-sensitive character set.

SET SHIFT[INOUT] {VIS[IBLE]|INV[ISIBLE]}

where:

SET SHIFT[INOUT]

Is the command, which may be abbreviated to SHIFT.

VIS[IBLE]

Allows shift characters to be visible.

INV[ISIBLE]

Keeps shift characters from being displayed.

The default setting is INVISIBLE.

SET SPACE

SET SPACE is an obsolete command similar to SET COLSEP. It allows you to specify the number of spaces SQL*Plus prints between columns of output.

SET SPACE num_of_spaces

where:

SET SPACE

Is the command, which may not be abbreviated.

num_of_spaces

Is the new setting for the number of spaces you want to print between columns. The default setting is one space.

The following example shows how SET SPACE works by changing the spacing between columns from one to five spaces:

SQL> SELECT 'A' a, 'B' b FROM dual;

A B
- -
A B

SQL> SET SPACE 5
SQL> SELECT 'A' a, 'B' b FROM dual;

A     B
-     -
A     B

Issuing SET SPACE 5 has the exact same effect as if you were to issue SET COLSEP " “. In fact, the two settings are kept in sync with one another. The SET SPACE command will change the COLSEP setting to match.

SET TAB

The TAB setting controls whether or not SQL*Plus uses tab characters when generating whitespace in terminal output. This setting is a throwback to the days when terminal connections ran at very slow data rates, such as 1200 bits per second.

SET TAB {OFF|ON}

where:

SET TAB

Is the command, which may not be abbreviated.

ON

Is the default setting, and allows SQL*Plus to insert tabs into the output rather than displaying a large number of space characters.

OFF

Forces SQL*Plus to use space characters for all whitespace.

The default setting is ON, which allows SQL*Plus to use tab characters in the output.

SET TRIMOUT

The TRIMOUT setting controls whether or not SQL*Plus displays any trailing spaces that may occur at the end of a line. The default setting is ON, which causes SQL*Plus to display only up to the last non-blank character on a line.

SET TRIM[OUT] {ON|OFF}

where:

SET TRIM[OUT]

Is the command, which may be abbreviated to SET TRIM.

ON

Causes SQL*Plus to trim any trailing spaces from each line before it is displayed. This is the default setting.

OFF

Causes SQL*Plus to display all characters on a line, even the trailing spaces.

The default setting of ON usually works well when displaying data on a terminal, so there’s rarely a reason to turn this setting off. TRIMOUT has no effect on spooled output. If you are spooling output to a file, the TRIMSPOOL setting controls whether or not trailing spaces are spooled as well.

SET TRIMSPOOL

The TRIMSPOOL setting controls whether or not SQL*Plus writes trailing spaces when spooling data to a file. The default setting is OFF, which causes SQL*Plus to write each line to the spool file in its entirety, trailing spaces and all.

SET TRIMS[POOL] {ON|OFF}

where:

SET TRIMS[POOL]

Is the command, which may be abbreviated to SET TRIMS.

ON

Causes SQL*Plus to trim any trailing spaces from each line before it is written to the spool file.

OFF

Causes SQL*Plus to write all characters of a line to the spool file, even the trailing spaces. This is the default setting.

If you are spooling data to a file in order to load it into another program, you will want to leave TRIMSPOOL ON. Otherwise, the program reading the spool file might return errors because the records are shorter than expected.

SET TRUNCATE

SET TRUNCATE is an obsolete command that gives you the same choice as SET WRAP. You can choose whether or not to truncate lines that are longer than the LINESIZE setting.

SET TRU[NCATE] {OFF|ON}

where:

SET TRU[NCATE]

Is the command, which may be abbreviated to TRU.

OFF

Is the default setting, and allows long lines to be wrapped.

ON

Causes long lines of output to be truncated to match the current LINESIZE setting.

TRUNCATE and WRAP both affect the same internal setting. Turning one on results in the other being turned off, and vice versa. For example:

SQL> SHOW WRAP
wrap : lines will be wrapped
SQL> SET TRUNCATE ON
SQL> SHOW WRAP
wrap : lines will be truncated

Tip

While you can issue the SHOW WRAP command to see the current value of the WRAP setting, you cannot issue SHOW TRUNCATE. The SHOW command does not recognize TRUNCATE as a valid SQL*Plus setting.

When you select data that is longer than the LINESIZE and the WRAP setting is off, some versions of SQL*Plus will print a warning message telling you that your rows may be truncated.

SET UNDERLINE

With the SET UNDERLINE command, you can control the character used to underline column headings. You can also control whether or not column headings are underlined at all.

SET UND[ERLINE] {underline_char | {ON|OFF}}

where:

SET UND[ERLINE]

Is the command, which may be abbreviated to SET UND.

underline_char

Is the character you want to use when underlining column headings. By default, a dash character (-) is used.

ON

Causes column headings to be underlined, and resets the underline character back to the dash.

OFF

Keeps column headings from being underlined.

The following example shows the underline character being changed to an asterisk:

SQL> SET UNDERLINE *
SQL> SELECT USER FROM dual;

USER
******************************
JEFF

You can also use SET UNDERLINE to turn underlining off completely, for example:

SQL> SET UNDERLINE OFF
SQL> SELECT USER FROM dual;

USER
JEFF

One reason you might turn underlining off would be if you wanted some columns to print without any heading at all. First you would turn UNDERLINE off. Then you would define column headings for all columns with the COLUMN command. Those headings you did want to print would need to include the underlines as part of the heading definition. Other headings would be defined as empty strings.

SET WRAP

The WRAP setting controls how SQL*Plus prints lines that contain more characters than the current LINESIZE setting allows. With WRAP ON, long lines are wrapped around and continued on as many physical lines as necessary. With WRAP OFF, lines are truncated to match the LINESIZE setting.

SET WRA[P] {ON|OFF}

where:

SET WRA[P]

Is the command, which may be abbreviated to SET WRA.

ON

Causes long lines to be wrapped around to two or more physical lines, in order to print and still fit within the LINESIZE setting.

OFF

Causes long records to be truncated to the current LINESIZE setting.

The following example shows the results of issuing the same SELECT statement, once with WRAP turned on, and once with it turned off:

SQL> SET WRAP ON
SQL> SELECT * FROM ALL_VIEWS WHERE VIEW_NAME = 'ALL_VIEWS';

OWNER                          VIEW_NAME                      TEXT_LENGTH
------------------------------ ------------------------------ -----------
TEXT
-----------------------------------------------------------------------------
TYPE_TEXT_LENGTH
----------------
TYPE_TEXT
-----------------------------------------------------------------------------
OID_TEXT_LENGTH
---------------
OID_TEXT
-----------------------------------------------------------------------------
VIEW_TYPE_OWNER                VIEW_TYPE
------------------------------ ------------------------------
SYS                            ALL_VIEWS                              821
select u.name, o.name, v.textlength, v.text, t.typetextlength, t.typetext,



SQL> SET WRAP OFF
SQL> /
rows will be truncated

rows will be truncated

rows will be truncated

rows will be truncated

rows will be truncated

rows will be truncated


OWNER                          VIEW_NAME                     TEXT_LENGTH TEXT
------------------------------ ----------------------------- ----------- ----
SYS                            ALL_VIEWS                           821 select

As you can see, SQL*Plus displays several warning messages telling you that the rows you are about to see displayed may have been truncated.

Feedback Settings

The settings described in this section all control some aspect of the feedback SQL*Plus provides in response to the commands you issue. Feedback settings include the following:

AUTOPRINT

Controls whether or not SQL*Plus automatically prints bind variables after they are referenced.

DOCUMENT

Controls whether or not SQL*Plus prints documentation demarcated by the DOCUMENT command.

ECHO

Controls whether or not SQL*Plus displays commands from a command file as they are executed.

FEEDBACK

Controls whether or not, and when, SQL*Plus displays the number of rows affected by an SQL statement.

PAUSE

Controls whether or not SQL*Plus pauses after each page of output.

SERVEROUTPUT

Controls whether or not SQL*Plus prints output from PL/SQL routines.

SHOWMODE

Controls whether or not SQL*Plus displays the before and after values when you change a setting.

SQLPROMPT

Contains the text string used as the SQL*Plus command prompt.

TERMOUT

Controls whether or not SQL*Plus displays output generated by SQL statements in a command file.

TIME

Controls whether or not SQL*Plus displays the current time as part of the command prompt.

VERIFY

Controls whether or not SQL*Plus displays before and after images of lines containing substitution variables.

The following sections describe each of these settings:

SET AUTOPRINT

The AUTOPRINT setting controls whether or not SQL*Plus automatically prints the contents of any bind variables referenced by a PL/SQL block after it executes.

SET AUTOP[RINT] {OFF|ON}

where:

SET AUTOP[RINT]

Is the command, which may be abbreviated to SET AUTOP.

OFF

Keeps bind variables from being automatically printed after being referenced by a PL/SQL block. This is the default setting.

ON

Causes bind variables to be printed automatically, following the execution of any PL/SQL block or SQL statement that references them.

SET DOCUMENT

SET DOCUMENT controls whether or not SQL*Plus prints text created with the DOCUMENT command.

SET DOC[UMENT] {ON|OFF}

where:

SET DOC[UMENT]

Is the command, which may be abbreviated to SET DOC.

ON

Allows DOCUMENT text to be displayed. This is the default setting.

OFF

Keeps DOCUMENT text from being displayed.

This setting only affects the DOCUMENT command when it is issued from a command file. Say that you had a file with the following lines:

DOCUMENT
This is documentation.
#

The following example shows the results of executing this file with the DOCUMENT setting on, and then with it off.

SQL> SET DOCUMENT ON
SQL> @c:adoc
DOC>This is documentation.
DOC>#
SQL> SET DOCUMENT OFF
SQL> @c:adoc

SET ECHO

Use SET ECHO to tell SQL*Plus whether or not you want the contents of command files to be echoed to the screen as they are executed.

SET ECHO {OFF|ON}

where:

SET ECHO

Is the command, which may not be abbreviated.

OFF

Keeps commands from being echoed to the screen while a command file is being executed. This is the default setting.

ON

Causes commands from a command file to be echoed to the screen as they are being executed.

SET ECHO is one of the few debugging tools SQL*Plus has, if indeed you could call it a debugging tool. It’s often very helpful to turn command echoing on while you are developing and testing a new script file. The following example shows the same script file being executed, once with ECHO on, and once with it off:

SQL> @c:aecho_test

D
-
X

SQL> SET ECHO ON
SQL> @c:aecho_test
SQL> SELECT * FROM dual;

D
-
X

For the second execution of the script, ECHO had been turned on, so the SELECT statement was displayed on the screen when SQL*Plus executed it.

Tip

If you are writing a script that spools data to a file, you will almost certainly want to leave ECHO off. Otherwise, the commands in your script would be spooled to the file along with the data.

SET FEEDBACK

The FEEDBACK setting controls whether or not SQL*Plus displays the number of records returned by a SELECT statement, deleted by a DELETE statement, updated by an UPDATE statement, or inserted by an INSERT statement. You can set a threshold below which you do not get any feedback regardless of whether the setting is on or not.

SET FEED[BACK] {OFF|ON|row_threshold}

where:

SET FEED[BACK]

Is the command, which may be abbreviated to SET FEED.

OFF

Turns feedback completely off. SQL*Plus will not tell you how many rows are affected by any SQL statements you issue.

ON

Turns feedback on, and is equivalent to SET FEEDBACK 1. For any SQL statement you issue, SQL*Plus will tell you how many rows were affected.

row_threshold

Allows you to specify a row threshold, and also turns feedback on if it is not already on. A row threshold causes SQL*Plus to print the row count returned by a SELECT statement only when that row count exceeds the threshold. The default value for the threshold is 6 rows. The row threshold applies only to the SELECT command. As long as feedback is on, the INSERT, DELETE, and UPDATE statements will always return the number of rows affected, regardless of the row threshold.

The following example shows a feedback message from a SELECT statement:

SQL> SET FEEDBACK 1
SQL> SELECT * FROM dual;

D
-
X

1 row selected.

In this example, feedback was set to 1 prior to executing the SELECT statement. That caused a feedback message to be displayed, even though the statement returned only one row.

SET PAUSE

You can use the SET PAUSE command to have SQL*Plus pause after each page of output when displaying rows returned by a query:

SET PAU[SE] {ON|OFF|pause_message}

where:

SET PAU[SE]

Is the command, which may be abbreviated to SET PAU.

ON

Causes SQL*Plus to pause after each page of output. The user must press ENTER to continue to the next page.

OFF

Turns the pause feature off. This is the default setting.

pause_message

Provides a message for SQL*Plus to display after each page when prompting the user to continue. This does not turn pause on. You must issue a separate SET PAUSE ON command to do that.

The following example shows how the pause feature works:

SQL> SET PAGESIZE 10
SQL> SET PAUSE ON
SQL> SET PAUSE "Press ENTER to continue..."
SQL> SELECT view_name FROM all_views;
Press ENTER to continue...

VIEW_NAME
------------------------------
ALL_ALL_TABLES
ALL_ARGUMENTS
ALL_CATALOG
ALL_CLUSTERS
ALL_CLUSTER_HASH_EXPRESSIONS
ALL_COLL_TYPES
ALL_COL_COMMENTS
Press ENTER to continue...

The PAGESIZE setting controls the number of lines printed on a page. In this example, PAGESIZE was set to 10, so SQL*Plus paused after every 10 lines of output.

SET SERVEROUTPUT

The SERVEROUTPUT setting controls whether or not SQL*Plus prints the output generated by the DBMS_OUTPUT package from PL/SQL procedures:

SET SERVEROUT[PUT] {OFF|ON} 
                   [SIZE buffer_size] 
                   [FOR[MAT] {WRA[PPED]|WOR[D_WRAPPED]|TRU[NCATED]}]

where:

SET SERVEROUT[PUT]

Is the command, which may be abbreviated to SET SERVEROUT.

OFF

Keeps PL/SQL output from being displayed. This is the default setting.

ON

Causes SQL*Plus to check for and display output generated by the DBMS_OUTPUT package after each PL/SQL block, procedure, or function you execute.

SIZE buffer_size

Sets the size of the buffer, in bytes, on the server that holds the output. This value can range from 2000 to 1,000,000, and controls the maximum amount of output any one PL/SQL routine can produce. The default buffer size is 2000 bytes.

WRA[PPED]

Causes the output to be wrapped within the current linesize. Line breaks will occur in the middle of words, if necessary.

WOR[D_WRAPPED]

Causes the output to be word-wrapped within the current linesize. Line breaks will only occur at word boundaries.

TRU[NCATED]

Causes any output longer than the linesize to be truncated.

By default, SQL*Plus does not display output from PL/SQL. The following example shows this:

SQL> BEGIN
  2    DBMS_OUTPUT.PUT_LINE('Hello World'),
  3  END;
  4  /

PL/SQL procedure successfully completed.

Now, the same block is executed again, after issuing a SET SERVEROUTPUT ON command:

SQL> SET SERVEROUTPUT ON
SQL> BEGIN
  2    DBMS_OUTPUT.PUT_LINE('Hello World'),
  3  END;
  4  /
Hello World

PL/SQL procedure successfully completed.

Older versions of SQL*Plus do not support the SIZE and FORMAT clauses of this command.

SET SHOWMODE

The SHOWMODE setting controls the feedback you get when you use the SET command to change a setting:

SET SHOW[MODE] {ON|OFF|BOTH}

where:

SET SHOW[MODE]

Is the command, which may be abbreviated to SET SHOW.

ON

Turns SHOWMODE on, causing SQL*Plus to list the before and after values of each setting you change using the SET command.

OFF

Turns SHOWMODE off, and is the default setting.

BOTH

Has the same effect as ON.

The following example shows the results of turning SHOWMODE on:

SQL> SET SHOWMODE ON
new: showmode BOTH
SQL> SET LINESIZE 132
old: linesize 80
new: linesize 132
SQL> SET PAGESIZE 60
old: pagesize 10
new: pagesize 60

You can see that with SHOWMODE on, the old and new values of each setting are displayed when they are changed.

SET SQLPROMPT

You can use the SET SQLPROMPT command to change the SQL*Plus command prompt:

SET SQLP[ROMPT] prompt_text

where

SET SQLP[ROMPT]

Is the command, which may be abbreviated to SET SQLP.

prompt_text

Is the new prompt text. The default prompt text is “SQL>”.

The following example shows the prompt being changed from “SQL>” to “SQL*Plus>”:

SQL> SET SQLPROMPT "SQL*Plus> "
SQL*Plus>

Some people like to set their prompt to the name of the database to which they are connected. One way to do this is to place the following commands in your login.sql file:

SET TERMOUT OFF
COLUMN dbname NEW_VALUE prompt_dbname
SELECT SUBSTR(global_name,1,INSTR(global_name,'.')-1) dbname 
       FROM global_name;
SET SQLPROMPT "&&prompt_dbname> "
SET TERMOUT ON

These commands will set your prompt to the global database name. The global name comes from the global_name view, and may or may not be the same as the connect string you used to connect to the database. By placing these commands in your login.sql file, you ensure that the prompt will be set automatically, based on the database you are connecting to, whenever you start SQL*Plus.

Tip

LOGIN.SQL is executed only when SQL*Plus starts. Using the CONNECT command to connect to another database will not cause the prompt to be changed to reflect the new connection.

The login.sql file was discussed earlier in this chapter, in the section titled Section 11.2.

SET TERMOUT

Controls whether or not SQL*Plus displays output generated by SQL statements, PL/SQL blocks, and SQL*Plus commands. This setting only applies when SQL*Plus is executing a script file. SQL*Plus always displays output from commands entered interactively.

SET TERM[OUT] {OFF|ON}

where:

SET TERM[OUT]

Is the command, which may be abbreviated to SET TERM.

OFF

Turns terminal output off.

ON

Turns terminal output on. This is the default setting.

Terminal output is often turned off while a command file is running to keep the user’s screen from becoming cluttered with query output and feedback messages.

SET TIME

The SET TIME command controls whether or not SQL*Plus displays the current time with each command prompt:

SET TI[ME] {OFF|ON}

where:

SET TI[ME]

Is the command, which may be abbreviated to SET TI.

OFF

Keeps the time from being displayed with the prompt. This is the default setting.

ON

Causes the time to be displayed as part of each prompt.

The following example shows the effect of issuing a SET TIME ON command:

SQL> SET TIME ON
22:44:41 SQL>

SET VERIFY

The VERIFY setting controls whether or not SQL*Plus displays before and after images of each line that contains a substitution variable:

SET VER[IFY] {OFF|ON}

where:

SET VER[IFY]

Is the command, which may be abbreviated to SET VER.

OFF

Turns verification off.

ON

Turns verification on. Lines containing substitution variables will be displayed before and after the substitution occurs. This is the default setting.

Verification is done only on lines that are part of a SQL statement or a PL/SQL block. When substitution occurs in a SQL*Plus command, before and after images are never displayed. The following example shows what verification looks like:

SQL> DEFINE dummy_char = 'X'
SQL> SELECT * FROM dual
  2   WHERE dummy = '&&dummy_char';
old   2:  where dummy = '&&dummy_char'
new   2:  where dummy = 'X'

D
-
X

Notice that line 2, which contained the reference to the &&dummy_char substitution variable, was displayed both before and after the reference to the variable was replaced by its value. If you don’t like this display, you can turn it off with SET VERIFY OFF.

Input Settings

Input settings control some aspects of the way commands are entered. Many of these settings allow you to specify alternative characters for command separators, PL/SQL block terminators, continuation prompts, and so forth. Other settings let you force commands to be uppercased, and allow you to enter blank lines as part of an SQL statement. Here is complete list of input settings:

BLOCKTERMINATOR

Specifies the character used to terminate entry of a PL/SQL block.

BUFFER

Allows you edit using multiple buffers.

CMDSEP

Controls whether or not you may enter multiple SQL*Plus commands on one line, and also specifies the character used to separate those commands.

SQLBLANKLINES

Controls whether or not you may enter blank lines as part of a SQL statement.

SQLCASE

Controls automatic case conversion of SQL statements and PL/SQL blocks.

SQLCONTINUE

Contains the text of the prompt you get when you use the SQL*Plus continuation character to continue a long command to a new line.

SQLNUMBER

Controls whether or not SQL*Plus uses the line number as a prompt when you enter a multiline SQL statement.

SQLPREFIX

Specifies the SQL*Plus prefix character, which allows you to execute a SQL*Plus command while entering a SQL statement or PL/SQL block into the buffer.

SQLTERMINATOR

Controls whether or not you can use a semicolon to execute a SQL statement, and also lets you specify a different character to be used for that purpose.

SUFFIX

Contains the default extension used for command files.

The following sections describe each of these settings.

BLOCKTERMINATOR

The BLOCKTERMINATOR setting controls the character used to terminate a PL/SQL block that is being entered into the buffer for editing:

SET BLO[CKTERMINATOR] block_term_char

where:

SET BLO[CKTERMINATOR]

Is the command, which may be abbreviated to SET BLO.

block_term_char

Is the new terminator character for use when entering PL/SQL blocks. The default value is a period.

When you enter a PL/SQL block into the buffer, you need a way to tell SQL*Plus when the block has ended. By default, the period can be used for this purpose, but you can use the SET BLOCKTERMINATOR command to change that. The following example shows how this is done by changing the block terminator to a pound sign character:

SQL> SET BLOCKTERMINATOR #
SQL> BEGIN
  2    DBMS_OUTPUT.PUT_LINE('PL/SQL is powerful.'),
  3  END;
  4  #
SQL>

Terminating the block this way leaves it in the buffer for you to edit. Do not confuse this with the use of the slash command, which both terminates and executes a block.

Tip

Changing the terminator to a slash character, by using SET BLOCKTERMINATOR /, prevents you from subsequently using the / character to execute the contents of the buffer.

BUFFER

The SET BUFFER command allows you to switch to another buffer for editing purposes:

SET BUF[FER] {buffer_name|SQL}

where:

SET BUF[FER]

Is the command, which may be abbreviated to SET BUF.

buffer_name

Is the name of the buffer you want to edit. You can make up any name you like. If the named buffer does not yet exist, SQL*Plus will create it for you.

SQL

Switches you to the SQL buffer. This is the default setting. The SQL buffer is the one used when you type in a SQL statement at the command prompt, and is also the only buffer from which you can execute a SQL statement (or PL/SQL block).

Changing the buffer has limited use, because you can only execute a statement from the SQL buffer. The GET, SAVE, and EDIT commands work, as do all the editing commands. The following example shows a second buffer being used to edit a statement that exists in a text file without disturbing the statement currently in the SQL buffer:

SQL> SHOW BUFFER
buffer SQL
SQL> SELECT * FROM employee
  2  
SQL> L
  1* SELECT * FROM employee
SQL> SET BUFFER project
SQL> L
No lines in PROJECT buffer.
SQL> GET c:aproject.sql
  1* SELECT * FROM project
SQL> I
  2  WHERE project_budget > 1000000
  3  
SQL> SAVE c:aproject.sql REPLACE
Wrote file c:aproject.sql
SQL> SET BUFFER SQL
SQL> L
  1* SELECT * FROM employee
SQL>

As you can see, using a second buffer made it possible to edit the SQL statement in the project.sql file without disturbing the statement currently in the SQL buffer. Of course, you could do the same thing more easily with the EDIT command, so SET BUFFER isn’t used much anymore.

CMDSEP

The SET CMDSEP command controls whether or not you can enter multiple commands on one line. The commands in question must both be SQL*Plus commands. SET CMDSEP is also used to change the character used to separate these commands:

SET CMDS[EP] {OFF|ON|separator_char

where:

SET CMDS[EP]

Is the command, which may be abbreviated to SET CMDS.

OFF

Turns the feature off, requiring you to enter each command on a separate line. This is the default setting.

ON

Allows you to enter multiple SQL*Plus commands on one line, and resets the separator character back to the default of a semicolon.

separator_char

Causes SQL*Plus to recognize the specified character as the command separator. You won’t be allowed to make the command separator an alphabetic, numeric, or space character. This character may optionally be enclosed in either single or double quotes. In some cases, such as when you change it to a semicolon, you will need the quotes.

The following example turns this feature on, sets the separator character to an exclamation point, and shows how two commands may be placed on one line:

SQL> SET CMDSEP ON
SQL> SET CMDSEP "!"
SQL> SHOW CMDSEP! SHOW BUFFER!
cmdsep "!" (hex 21)
buffer SQL
SQL>

SQLBLANKLINES

The SQLBLANKLINES setting is a new feature in version 8.1 of SQL*Plus, and allows SQL statements to contain embedded blank lines:

SET SQLBLANKLINES {OFF|ON}

where:

SET SQLBLANKLINES

Is the command.

OFF

Turns this feature off. This is the default setting, and does not allow a SQL statement to have embedded blank lines.

ON

Turns the feature on, and allows you to enter a SQL statement with an embedded blank line.

Pressing ENTER on a blank line while typing a SQL statement into SQL*Plus normally signals the end of the statement. The statement is then placed into the buffer, and you then have the option of making further edits or of executing the statement. Turning SQLBLANKLINES on allows you to put a blank line in the middle of your statement, as the following example demonstrates:

SQL> SET SQLBLANKLINES ON
SQL> SELECT
  2  *
  3  
  4  FROM EMPLOYEE
  5  
SQL>

This feature was added to SQL*Plus to allow it to execute existing Server Manager scripts, such as CATPROC.SQL, without having to go through and modify all the SQL statements in those scripts. Unlike SQL*Plus, the Server Manager utility allows blank lines in a SQL statement.

Tip

Oracle plans to desupport Server Manager at some future date, leaving SQL*Plus as the only command-line interface into the Oracle database.

SQLCASE

The SQLCASE setting controls whether or not SQL*Plus automatically uppercases or lowercases SQL statements and PL/SQL blocks as they are transmitted to the server for execution:

SET SQLC[ASE] {MIXED|UPPER|LOWER}

where:

SET SQLC[ASE]

Is the command, which may be abbreviate to SET SQLC.

MIXED

Leaves each statement just as you entered it. This is the default setting.

UPPER

Uppercases each statement, including any quoted text literals.

LOWER

Lowercases each statement, including any quoted text literals.

Be careful when changing this setting. Any case conversions SQL*Plus does will affect not only your SQL statement keywords, but also any quoted text literals as well. This is seldom desirable behavior. The following example demonstrates this.

SQL> SET SQLCASE UPPER
SQL> SELECT * FROM dual WHERE dummy='x';

D
-
X

You can see that the SELECT statement succeeded, even though the lowercase “x” in the WHERE clause does not match the uppercase “X” in the dummy column.

Case conversion occurs when the statement is transmitted to the database server. The contents of the buffer will always reflect what you actually typed.

SQLCONTINUE

The SQLCONTINUE setting controls the prompt used when you continue a statement to a second line, using the SQL*Plus continuation character:

SET SQLCO[NTINUE] continuation_prompt

where:

SET SQLCO[NTINUE]

Is the command, which may be abbreviated to SET SQLCO.

continuation_prompt

Is the new continuation prompt. The default value is “>” — the greater-than character. The prompt may optionally be enclosed in either single or double quotes.

The following example shows the effect of changing this setting:

SQL> SET SQLCONTINUE "Continue > "
SQL> DESCRIBE -
Continue >

Notice that the SQL*Plus continuation character, a dash, was used following the DESCRIBE command. The continuation prompt is used only when you use the continuation character to continue a command to a new line. It is not used when you enter a multiline SQL statement.

SQLNUMBER

The SQLNUMBER setting controls whether or not SQL*Plus uses the line number as a prompt when you enter a multiline SQL statement:

SET SQLN[UMBER] {OFF|ON}

where:

SET SQLN[UMBER]

Is the command, which may be abbreviated to SET SQLN.

OFF

Causes SQL*Plus to use the same prompt for all lines of a SQL statement or PL/SQL block.

ON

Causes SQL*Plus to use the line number as the prompt for the second, and subsequent, lines of an SQL statement or PL/SQL block. This is the default setting.

The following example shows the difference between the ON and OFF settings:

SQL> SET SQLNUMBER ON
SQL> SELECT
  2  * 
  3  FROM dual
  4  
SQL> SET SQLNUMBER OFF
SQL> SELECT
SQL> *
SQL> FROM dual
SQL>

I can’t imagine any reason to ever turn this setting off. Look at the first and second statements in the example. It’s immediately obvious that the three lines of the first query all belong together as one statement. This is not so obvious with the second statement — you have to think about it a bit. The visual cue provided by the line numbers is missing, making you take more time to figure out what you are really looking at.

SQLPREFIX

The SQLPREFIX setting controls the SQL*Plus prefix character. The prefix character allows you to execute a SQL*Plus command while in the middle of entering an SQL statement (or PL/SQL block).

SET SQLPRE[FIX] prefix_char

where:

SET SQLPRE[FIX]

Is the command, which may be abbreviated to SET SQLPRE.

prefix_char

Is the new prefix character. The default prefix character is a pound sign. This may optionally be enclosed in either single or double quotes.

The following example shows how the prefix character is used by using it to execute a DESCRIBE command while entering a SELECT statement:

SQL> SELECT 
  2  #DESCRIBE EMPLOYEE
 Name                            Null?    Type
 ------------------------------- -------- ----
 EMPLOYEE_ID                     NOT NULL NUMBER
 EMPLOYEE_NAME                            VARCHAR2(40
 EMPLOYEE_HIRE_DATE                       DATE
 EMPLOYEE_TERMINATION_DATE                DATE
 EMPLOYEE_BILLING_RATE                    NUMBER

  2  employee_id, employee_name
  3  FROM employee
  4

This ability to execute a SQL*Plus command (and it must be a SQL*Plus command) while entering a SQL statement can come in handy when you need to quickly refresh your memory regarding the column names in the table.

SQLTERMINATOR

The SQLTERMINATOR setting controls whether or not SQL*Plus allows you to use a semicolon to terminate and execute a SQL statement. This setting also controls the specific character used for this purpose.

SET SQLT[ERMINATOR] {OFF|ON|term_char}

where:

SET SQLT[ERMINATOR]

Is the command, which may be abbreviated to SET SQLT.

OFF

Turns off the feature that allows you to terminate and execute a SQL statement using a semicolon or other character.

ON

Turns this feature on, and resets the terminator character to the default value of a semicolon.

term_char

Is the character you want to use as a statement terminator. This may optionally be enclosed in single or double quotes.

The following example changes the terminator character to a percent sign and uses it to terminate and execute a SELECT statement:

SQL> SET SQLTERMINATOR "%"
SQL> SELECT employee_name FROM employee%

EMPLOYEE_NAME
----------------------------------------
Bohdan Khmelnytsky
Pavlo Chubynsky
Ivan Mazepa
Taras Shevchenko
...

If the feature had been turned off in the above example, the percent sign would have been placed in the buffer as part of the SELECT statement.

SUFFIX

The SUFFIX setting controls the default extension used for command files:

SET SUF[FIX] extension

where:

SET SUF[FIX]

Is the command, which may be abbreviated to SET SUF.

extension

Is the default extension to use when referring to SQL files. The default value for this setting is SQL.

This setting is used by commands such as START, @, SAVE, and others that refer to SQL files. It does not apply to files created with the SPOOL command.

Operational Settings

Operational settings control various aspects of how your commands are executed and how SQL*Plus interacts with the database. You can control the following items:

APPINFO

Controls automatic registration of command files using the DBMS_APPLICATION_INFO package.

ARRAYSIZE

Is the number of rows SQL*Plus will return at once from the database.

AUTOCOMMIT

Controls whether or not SQL*Plus automatically commits your changes.

CLOSECURSOR

Controls whether or not SQL*Plus keeps the statement cursor open all the time.

COMPATIBILITY

Controls whether SQL*Plus acts as if it is connected to a version 7 database or a version 8 database.

COPYCOMMIT

Controls how often SQL*Plus commits during the execution of a COPY command.

FLAGGER

Controls whether or not SQL*Plus checks your statements for compliance with ANSI/ISO syntax.

FLUSH

Controls whether or not output may be buffered.

The following sections describe the operational settings in detail.

SET APPINFO

The APPINFO setting controls whether or not SQL*Plus automatically registers command files using the DBMS_APPLICATION_INFO package:

SET APPI[NFO] {OFF|ON|app_text}

where:

SET APPI[NFO]

Is the command, which may be abbreviated to SET APP.

OFF

Disables the automatic registration of command file names. With this off, SQL*Plus will make an entry using the current value of app_text whenever you execute a command file.

ON

Enables the automatic registration of command files. This is the default setting.

app_text

Provides a text string that is used instead of the command file name. The default setting for this is “SQL*Plus”.

The DBMS_APPLICATION_INFO package is defined in the Oracle Tuning manual. Among other things, this package controls the contents of the module field in both the V$SESSION and V$SQLAREA views.

Whenever you connect to a database, SQL*Plus registers itself as the active application by making a call to the DBMS_APPLICATION_INFO.SET_MODULE procedure. This sets the module name for your session to “SQL*Plus”. This is reflected in the v$session view, as the following example demonstrates:

SQL> SELECT module FROM v$session WHERE username=USER;

MODULE
------------------------------------------------
SQL*Plus

SQL*Plus has the ability to update the module name whenever you execute a command file. The module name can be set to either the command file name or to some arbitrary text that you specify. The default setting for APPINFO causes SQL*Plus to register the name of each command file you execute. So, if you execute a command file from one SQL*Plus session and query the v$session view from a second SQL*Plus session, you will get results like the following:

SQL> SELECT module FROM v$session WHERE username='JEFF';

MODULE
------------------------------------------------
01@ c:aproject_hours_dollars.SQL

The module column now tells you the name of the command file being executed by the user named JEFF. SQL*Plus actually crams in a bit more information than just the filename. You can break down the format of the module field as follows:

NL@tFFFFFFFF

where:

NL

Is the nesting level. Command files executed from the SQL*Plus prompt will have a 01 in this position. If one command file executes another command file, then the nesting level will be 02, indicating that a second command file was invoked. The deeper the command files are nested, the larger this number becomes.

@

Is a constant.

t

Is a flag indicating whether or not SQL*Plus had to truncate the name of the command file in order for it to fit within the module field. The maximum length of a module is 48 bytes. If the filename was truncated, this value will be a less-than sign (“<”).

FFFFFFFF

Is the filename, or as much as will fit within 48 characters.

You may find that you don’t care about command file names, but that you just want to know when users are using SQL*Plus. You can accomplish that by setting APPINFO to OFF. In that case, SQL*Plus will still register itself, but will not subsequently change the module name. It will always be “SQL*Plus”. For this to apply to all users, you would need to place the setting in each user’s global or site profile.

An additional option is to supply a fixed text string that SQL*Plus can use instead of a filename. This string is passed as the module name whenever a command file is executed. The result is that while you will know that a command file is being executed, you won’t know which one.

SET ARRAYSIZE

The ARRAYSIZE setting controls the number of rows SQL*Plus fetches from the database at one time.

SET ARRAY[SIZE] array_size

where:

SET ARRAY[SIZE]

Is the command, which may be abbreviated to SET ARRAY.

array_size

Is the number of rows fetched at one time. The default value is 15. The allowed range is from 1 to 5000.

Increasing the arraysize allows SQL*Plus to return more rows in one fetch, thus lessening the required number of network round trips between it and the database server. The tradeoff is that larger arraysize settings require more memory. Using the default value of 15, SQL*Plus would require 10 fetches to return 150 rows from a query. By increasing the arraysize to 50, you reduce the number of fetches to three.

SET AUTOCOMMIT

The autocommit setting controls whether or not SQL*Plus automatically commits changes you make to the database. It also controls how often those changes are committed.

SET AUTO[COMMIT] {OFF|ON|IMMEDIATE|statement_count}

where:

SET AUTO[COMMIT]

Is the command, which may be abbreviated to SET AUTO.

OFF

Turns autocommit off, and requires you to commit (or rollback) changes manually. This is the default setting.

ON

Causes SQL*Plus to issue a COMMIT after each successful SQL statement or PL/SQL block you execute.

IMMEDIATE

Has the same effect as ON.

statement_count

Causes SQL*Plus to issue a COMMIT after successfully executing the specified number of SQL queries or PL/SQL blocks. This value may range from 1 to 2,000,000.

When you set autocommit to occur after a specified number of successful SQL statements, be aware that manually executing a COMMIT, a ROLLBACK, or another SET AUTOCOMMIT command will cause the counter to be reset back to zero. Take a look at the following example:

SET AUTOCOMMIT 5
DELETE FROM project_hours WHERE employee_id = 101 AND project_id = 1001;
DELETE FROM project_hours WHERE employee_id = 102 AND project_id = 1001;
COMMIT;
DELETE FROM project_hours WHERE employee_id = 103 AND project_id = 1001;
DELETE FROM project_hours WHERE employee_id = 104 AND project_id = 1001;
DELETE FROM project_hours WHERE employee_id = 105 AND project_id = 1001;
DELETE FROM project_hours WHERE employee_id = 106 AND project_id = 1001;
DELETE FROM project_hours WHERE employee_id = 107 AND project_id = 1001;

The COMMIT statement in the fourth line will cause the counter to be reset. Counting will start over again, and five more SQL statements must be executed successfully before an automatic commit occurs.

SET CLOSECURSOR

The CLOSECURSOR setting controls whether or not SQL*Plus closes the cursor used to execute an SQL statement after the statement has executed:

SET CLOSECUR[SOR] {OFF|ON}

where:

SET CLOSECUR[SOR]

Is the command, which may be abbreviated to SET CLOSECUR.

OFF

Causes SQL*Plus to leave the cursor open for use by subsequent SQL statements. This is the default setting.

ON

Causes SQL*Plus to close the cursor after a SQL statement has been executed.

While you normally think of a cursor only in the context of returning data from a SELECT statement, Oracle also uses cursors to execute other SQL statements, such as DELETE, INSERT, UPDATE, and so forth. The same cursor can be used to execute many SQL statements, so SQL*Plus leaves it open all the time by default.

SET COMPATIBILITY

Use SET COMPATIBILITY to tell SQL*Plus the version of Oracle to which you are connected:

SET COM[PATIBILITY] {V7|V8|NATIVE}

where:

SET COM[PATIBILITY]

Is the command, which may be abbreviated to SET COM.

V7

Tells SQL*Plus you are connected to a version 7 server, or that you want SQL*Plus to act as if you were.

V8

Tells SQL*Plus you are connected to a version 8 database.

NATIVE

Causes SQL*Plus to automatically determine the compatibility setting based on the version of the database to which you are connected. This is the default setting.

This setting controls the way SQL statements are transmitted to the server and the way the results are brought back. It’s usually best just to leave this at the default setting, which causes SQL*Plus to automatically choose the correct method based on the database to which you are connected.

SET COPYCOMMIT

The copycommit setting controls how often SQL*Plus commits during execution of a COPY command:

SET COPYC[OMMIT] batch_count

where:

SET COPYC[OMMIT]

Is the command, which may be abbreviated to SET COPYC.

batch_count

Is the maximum number of uncommitted batches you want to allow during a copy operation. After this many batches are sent to the server, SQL*Plus commits the changes and resets the counter before sending another. The default value is 0, which means that SQL*Plus commits changes only when the COPY command is finished. The maximum value for this setting is 5000.

Normally, when you execute a COPY command, SQL*Plus copies all the rows from the source table to the destination table, then commits those changes. This can make for a rather large transaction if you are copying a large number of records, and your rollback segments may not be big enough to accommodate it. You can use SET COPYCOMMIT to have SQL*Plus periodically commit the changes, thus reducing the transaction size.

The copycommit setting works in conjunction with the arraysize setting. The arraysize setting controls the number of rows in a batch. The copycommit setting controls how many batches are copied before committing. The number of rows copied before each commit is equal to ARRAYSIZE * COPYCOMMIT. Take a look at this example:

SET ARRAYSIZE 15
SET COPYCOMMIT 10
COPY TO jonathan/chatham@jonathan
CREATE employee_copy
USING SELECT * FROM employee;

Because the arraysize is 15 and the copycommit setting is 10, the COPY statement shown here will commit changes after every 150 rows (15 * 10).

SET FLAGGER

Use SET FLAGGER to have your SQL statements checked for conformance to ANSI/ISO SQL92 syntax. There are three compliance levels to choose from: entry, intermediate, and full.

SET FLAGGER {OFF|ENTRY|INTERMED[IATE]|FULL}

where:

SET FLAGGER

Is the command, which may not be abbreviated.

OFF

Turns this feature off. This is the default setting.

ENTRY

Allows SQL statements that use only the entry-level features of the standard.

INTERMED[IATE]

Allows SQL statements that use the intermediate-level features of the standard.

FULL

Allows any SQL statement that is defined in the standard.

Using the SET FLAGGER command has the same effect as executing the ALTER DATABASE SET FLAGGER command. However, SET FLAGGER is a SQL*Plus command, so you can execute it even before connecting to the database. Once you’ve turned this feature on, any attempt to execute a nonconforming command will result in an error message like the following:

ERROR:
ORA-00097: Use of Oracle SQL feature not in SQL92 Entry Level

This feature is useful if you are writing software for the federal government and are required to deliver an implementation that uses no non-standard, vendor-specific features.

SET FLUSH

The flush setting indicates whether or not the host operating system is allowed to buffer output:

SET FLU[SH] {OFF|ON}

where:

SET FLU[SH]

Is the command, which may be abbreviated to SET FLU.

OFF

Allows output to be buffered.

ON

Causes output to be displayed immediately.

If you are running a command file, turning flush off might keep you from seeing any output until SQL*Plus is finished executing that file.

Substitution Variable Settings

Substitution variable settings allow you to change the way SQL*Plus handles substitution variables. The following settings make up this category:

CONCAT

Specifies the concatenation character, which marks the end of a substitution variable.

DEFINE

Specifies the character used to mark a substitution variable.

ESCAPE

Specifies the escape character.

SCAN

Controls whether or not the substitution feature is enabled.

Most of these settings are described, with examples, in Chapter 4. They are described here as well, in the following sections.

SET CONCAT

The SET CONCAT command allows you to change the character used to terminate a substitution variable reference. You can also use the command to turn the feature off so that SQL*Plus doesn’t recognize any character as the terminator.

SET CON[CAT] {OFF|ON|concat_char}

where:

SET CON[CAT]

Is the command, which may be abbreviated to SETCON.

OFF

Turns this feature off completely. SQL*Plus won’t recognize any character as the termination character for substitution variable names.

ON

Turns this feature back on, and resets the character back to the default value of a period.

concat_char

Is the new termination character. The default value is a period.

This setting is important only when you immediately follow a substitution variable name with characters that SQL*Plus might interpret as part of the name. Consider the following example:

DEFINE table="PROJECT"
SELECT &&table._name FROM &&table;

The period (or concatenation character) in the SELECT statement is used to terminate the reference to &&table. Without the period, SQL*Plus would recognize &&table_name as the substitution variable.

Tip

The concatenation character is never left in the line. When SQL*Plus substitutes a value for the variable, the concatenation character goes away along with the variable name.

SET DEFINE

The SET DEFINE command allows you to change the prefix character used to mark substitution variables. You can also use SET DEFINE to turn variable substitution off.

SET DEF[INE] {OFF|ON|prefix_char}

where:

SET DEF[INE]

Is the command, which may be abbreviated to SET DEF.

OFF

Disables variable substitution.

ON

Enables variable substitution, and resets the substitution prefix character back to the default ampersand (&) character. Variable substitution is on by default.

prefix_char

Is the new substitution prefix character.

When you start SQL*Plus, variable substitution will be on by default, and the default prefix character is an ampersand. If you are running a script that uses ampersands in text strings, you may want to change the prefix character to something else. If your script does not use substitution variables, you may find it easiest to just turn the feature off completely.

SET ESCAPE

Use SET ESCAPE to specify the character used to escape the substitution variable prefix:

SET ESC[APE] {OFF|ON|escape_char}

where:

SET ESC[APE]

Is the command, which may be abbreviated to SET ESC.

OFF

Turns the escape feature off completely. SQL*Plus will not recognize any character as an escape character. This is the default setting.

ON

Enables the escape feature, and resets the escape character back to the default value, a backslash ().

escape_char

Is the new escape character. By default, this is a backslash.

You use the escape character when you want to place an ampersand in a command and you don’t want that ampersand interpreted as a substitution variable prefix character. The following example shows a case where this can be a problem:

SQL> SELECT 'O''Reilly & Associates' FROM dual;
Enter value for associates:

The ampersand in front of the word “Associates” causes SQL*Plus to interpret it as substitution variable name. To work around this behavior, you can turn the escape feature on and precede the ampersand with a backslash. Here is an example:

SQL> SET ESCAPE ON
SQL> SELECT 'O''Reilly & Associates' FROM dual;

'O''REILLY&ASSOCIATES
---------------------
O'Reilly & Associates

You can also use the SET ESCAPE command to change the escape character to something other than a backslash.

SET SCAN

SET SCAN is an obsolete command that allows you to choose whether or not SQL*Plus scans for substitution variables:

SET SCAN {OFF|ON}
SET SCAN

Is the command, which may not be abbreviated.

OFF

Disables variable substitution, and has the same effect as SET DEFINE OFF.

ON

Enables variable substitution, and has the same effect as SET DEFINE ON.

The SET SCAN command duplicates functionality provided by the SET DEFINE command.

Large Object Settings

Large object settings control the way SQL*Plus handles columns with a datatype of LONG. The most commonly adjusted setting is the LONG setting, which controls the maximum number of characters SQL*Plus will display from a LONG. The complete list of LONG settings is shown here:

LOBOFFSET

An index into the LONG column, specifying the first character to be displayed.

LONG

Specifies the maximum number of characters to display from a LONG column.

LONGCHUNKSIZE

Controls the number of characters retrieved from a LONG at one time.

Chapter 7, contains examples showing how to use these three settings.

SET LOBOFFSET

The LOBOFFSET setting represents an index into a LONG column. When SQL*Plus displays a LONG, it begins with the character pointed to by LOBOFFSET.

SET LOBOF[FSET] offset

where:

SET LOBOF[FSET]

Is the command, which may be abbreviated to SET LOBOF.

offset

Is the offset used when retrieving LONG values, and represents the first character you want to display.

Using the LOBOFFSET setting in conjunction with the LONG setting allows you to print any arbitrary substring from a LONG column.

SET LONG

The LONG setting controls the number of characters displayed by SQL*Plus from any LONG columns returned by a query:

SET LONG long_length

where:

SET LONG

Is the command, which may not be abbreviated.

long_length

Represents the number of characters you want displayed from any LONG columns you select from the database. The default setting is to display 80 characters.

SET LONGCHUNKSIZE

The LONGCHUNKSIZE is a performance-related setting. It controls the number of characters retrieved at one time from a LONG column.

SET LONGC[HUNKSIZE] size

where:

SET LONGC[HUNKSIZE]

Is the command, which may be abbreviated to SET LONGC.

size

Is the number of characters you want to retrieve from a LONG column in one fetch. The default value is 80.

With the default setting of 80 characters, SQL*Plus will need 10 round trips to the database to retrieve an 800-character LONG value. These network round trips take time, so you will tend to get better performance by increasing this setting. If you can afford the memory, make LONGCHUNKSIZE equal to the LONG setting. That way, the entire LONG value will be retrieved in one fetch.

Tuning and Timing Settings

Two settings are useful when tuning SQL statements. They are:

AUTOTRACE

Enables the automatic display of the execution plan and execution statistics for a SQL statement.

TIMING

Controls whether or not SQL*Plus displays the elapsed execution time for each SQL statement or PL/SQL block.

Chapter 8, describes the timing features of SQL*Plus in detail, and also explains how to interpret the execution plan for a SQL statement.

SET AUTOTRACE

The AUTOTRACE setting is used to control whether or not SQL*Plus displays the execution plan and statistics for each SQL statement as it is executed:

SET AUTOT[RACE] {OFF|ON|TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]

where:

SET AUTOT[RACE]

Is the command, which may be abbreviated to SETAUTOT.

OFF

Disables the autotrace feature. SQL*Plus will not display the execution plan or the statistics for each SQL statement.

ON

Turns the autotrace feature on. If no other parameters are supplied, SQL*Plus will default to displaying the statistics. SET AUTOTRACE ON is equivalent to SET AUTOTRACE ON STATISTICS.

TRACE[ONLY]

Inhibits the display of any data returned when the SQL statement in question is a SELECT statement.

EXP[LAIN]

Causes SQL*Plus to display the execution plan for each SQL statement you execute.

STAT[ISTICS]

Causes SQL*Plus to display execution statistics for each SQL statement you execute.

See Chapter 8 for comprehensive examples showing how to use the autotrace feature of SQL*Plus. Chapter 8 also shows you how to interpret the execution plan output and describes the operations that may be used in that plan.

SET TIMING

The TIMING setting controls whether or not SQL*Plus displays the elapsed time for each SQL statement or PL/SQL block you execute:

SET TIMI[NG] {OFF|ON}

where:

SET TIMI[NG]

Is the command, which may be abbreviated to SET TIMI.

OFF

Turns the timing feature off. This is the default setting.

ON

Enables the display of elapsed execution time for SQL statements and PL/SQL blocks.

See Chapter 8, for examples of this command.

Database Administration Settings

Database administration settings may be used only by database administrators, and control the way SQL*Plus operates when performing administrative tasks such as database recovery. These settings are listed below:

AUTORECOVERY

Causes the RECOVER command to run without user intervention.

LOGSOURCE

Tells SQL*Plus where to find archive log files for recovery.

SET AUTORECOVERY

The AUTORECOVERY option causes the RECOVER command to run without user intervention, as long as the archived log files are in the destination pointed to by the LOG_ARCHIVE_DEST parameter and the names conform to the LOG_ARCHIVE_FORMAT parameter.

SET AUTORECOVERY {OFF|ON}

where:

SET AUTORECOVERY

Is the command, which may not be abbreviated.

OFF

Turns autorecovery off. This is the default setting.

ON

Turns autorecovery on, causing the RECOVER command to run without user intervention.

Chapter 10, talks about recovery in more detail.

SET LOGSOURCE

The LOGSOURCE setting specifies the location of the archive log files, and is referenced during recovery:

SET LOGSOURCE logpath

where:

SET LOGSOURCE

Is the command, which may not be abbreviated.

logpath

Is the path to the directory containing the archived redo log files.

Miscellaneous Settings

This section describes the following three miscellaneous settings:

COPYTYPECHECK

Controls whether or not type checking is done for the COPY command.

EDITFILE

Specifies the name of the work file used when you invoke the EDIT command.

INSTANCE

Specifies the default database instance to use with the CONNECT command.

SET COPYTYPECHECK

The COPYTYPECHECK setting controls whether or not SQL*Plus checks the datatypes when you use the COPY command to move data between two databases:

SET COPYTYPECHECK {OFF|ON}

where:

SET COPYTYPECHECK

Is the command, which may not be abbreviated.

OFF

Turns type checking off.

ON

Enables type checking. This is the default setting.

This option was created specifically for use when copying data to a DB2 database.

SET EDITFILE

The SET EDITFILE command lets you change the name of the work file that is created when you use the EDIT command to edit the SQL statement in the buffer:

SET EDITF[ILE] edit_filename

where:

SET EDITF[ILE]

Is the command, which may be abbreviated to SET EDITF.

edit_filename

Is the filename you want SQL*Plus to use when you issue an EDIT command. The default value is afiedt.buf. The filename you specify may optionally include a path.

If you do not include an extension as part of the filename, the current value of the SUFFIX setting will be used as the extension.

SET INSTANCE

The SET INSTANCE command allows you to specify a default database to connect to when you use the CONNECT command without specifying a service name. You cannot issue this command while connected to a database; you must disconnect first.

SET INSTANCE [service_name|LOCAL]

where:

SET INSTANCE

Is the command, which may not be abbreviated. Issuing the command SET INSTANCE with no parameters has the same effect as SET INSTANCE LOCAL.

service_name

Is a Net8 (SQL*Net) service name.

LOCAL

Sets the default instance to be your local database. This is the default setting. In a Windows environment, the local database is the one specified by the LOCAL registry setting.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset