Skip Headers

SQL*Plus User's Guide and Reference
Release 9.2

Part Number A90842-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to next page

13
SQL*Plus Command Reference

This chapter contains descriptions of the SQL*Plus commands available in command-line and iSQL*Plus interfaces listed alphabetically. Each description contains the following parts:

Syntax

Shows how to enter the command and provides a brief description of the basic uses of the command. Refer to "Conventions in Code Examples" for an explanation of the syntax notation

Terms

Describes the function of each term or clause appearing in the syntax.

Usage

Provides additional information on uses of the command and on how the command works.

Examples

Gives one or more examples of the command.

A summary table that lists and briefly describes SQL*Plus commands precedes the individual command descriptions.

You can continue a long SQL*Plus command by typing a hyphen at the end of the line and pressing [Return]. If you wish, you can type a space before typing the hyphen. SQL*Plus displays a right angle-bracket (>) as a prompt for each additional line.

You do not need to end a SQL*Plus command with a semicolon. When you finish entering the command, you can just press [Return]. If you wish, however, you can enter a semicolon at the end of a SQL*Plus command.

SQL*Plus Command Summary

Command Description

@ ("at" sign)

Runs the SQL*PLus statements in the specified script. The script can be called from the local file system or from a web server.

@@ (double "at" sign)

Runs a script. This command is similar to the @ ("at" sign) command. It is useful for running nested scripts because it looks for the specified script in the same path as the script from which it was called.

/ (slash)

Executes the SQL command or PL/SQL block.

ACCEPT

Reads a line of input and stores it in a given user variable.

APPEND

Adds specified text to the end of the current line in the buffer.

ARCHIVE LOG

Starts or stops the automatic archiving of online redo log files, manually (explicitly) archives specified redo log files, or displays information about redo log files.

ATTRIBUTE

Specifies display characteristics for a given attribute of an Object Type column, and lists the current display characteristics for a single attribute or all attributes.

BREAK

Specifies where and how formatting will change in a report, or lists the current break definition.

BTITLE

Places and formats a specified title at the bottom of each report page, or lists the current BTITLE definition.

CHANGE

Changes text on the current line in the buffer.

CLEAR

Resets or erases the current clause or setting for the specified option, such as BREAKS or COLUMNS.

COLUMN

Specifies display characteristics for a given column, or lists the current display characteristics for a single column or for all columns.

COMPUTE

Calculates and prints summary lines, using various standard computations, on subsets of selected rows, or lists all COMPUTE definitions.

CONNECT

Connects a given user to Oracle.

COPY

Copies results from a query to a table in a local or remote database.

DEFINE

Specifies a user variable and assigns it a CHAR value, or lists the value and variable type of a single variable or all variables.

DEL

Deletes one or more lines of the buffer.

DESCRIBE

Lists the column definitions for the specified table, view, or synonym or the specifications for the specified function or procedure.

DISCONNECT

Commits pending changes to the database and logs the current user off Oracle, but does not exit SQL*Plus.

EDIT

Invokes a host operating system text editor on the contents of the specified file or on the contents of the buffer.

EXECUTE

Executes a single PL/SQL statement.

EXIT

Terminates SQL*Plus and returns control to the operating system.

GET

Loads a host operating system file into the SQL buffer.

HELP

Accesses the SQL*Plus help system.

HOST

Executes a host operating system command without leaving SQL*Plus.

INPUT

Adds one or more new lines after the current line in the buffer.

LIST

Lists one or more lines of the SQL buffer.

PASSWORD

Allows a password to be changed without echoing the password on an input device.

PAUSE

Displays the specified text, then waits for the user to press [Return].

PRINT

Displays the current value of a bind variable.

PROMPT

Sends the specified message to the user's screen.

QUIT

Terminates SQL*Plus and returns control to the operating system. QUIT is identical to EXIT.

RECOVER

Performs media recovery on one or more tablespaces, one or more datafiles, or the entire database.

REMARK

Begins a comment in a script.

REPFOOTER

Places and formats a specified report footer at the bottom of each report, or lists the current REPFOOTER definition.

REPHEADER

Places and formats a specified report header at the top of each report, or lists the current REPHEADER definition.

RUN

Lists and executes the SQL command or PL/SQL block currently stored in the SQL buffer.

SAVE

Saves the contents of the SQL buffer in a host operating system file (a script).

SET

Sets a system variable to alter the SQL*Plus environment for your current session.

SHOW

Shows the value of a SQL*Plus system variable or the current SQL*Plus environment.

SHUTDOWN

Shuts down a currently running Oracle instance.

SPOOL

Stores query results in an operating system file and, optionally, sends the file to a printer.

START

Executes the contents of the specified script. The script can only be called from a url.

STARTUP

Starts an Oracle instance and optionally mounts and opens a database.

STORE

Saves attributes of the current SQL*Plus environment in a host operating system file (a script).

TIMING

Records timing data for an elapsed period of time, lists the current timer's title and timing data, or lists the number of active timers.

TTITLE

Places and formats a specified title at the top of each report page, or lists the current TTITLE definition.

UNDEFINE

Deletes one or more user variables that you defined either explicitly (with the DEFINE command) or implicitly (with an argument to the START command).

VARIABLE

Declares a bind variable that can be referenced in PL/SQL.

WHENEVER OSERROR

Performs the specified action Exits SQL*Plus if an operating system command generates an error.

WHENEVER SQLERROR

Performs the specified action Exits SQL*Plus if a SQL command or PL/SQL block generates an error.

@ ("at" sign)

@{url|file_name[.ext] } [arg...]

Runs the SQL*Plus statements in the specified script. The script can be called from the local file system or from a web server. Only the url form is supported in iSQL*Plus.

Terms

Refer to the following for a description of the term or clause:

url

Specifies the Uniform Resource Locator of a script to run on the specified web server. SQL*Plus supports HTTP and FTP protocols.

file_name[.ext]

Represents the script you wish to run. If you omit ext, SQL*Plus assumes the default command-file extension (normally SQL). For information on changing the default extension, see the SUFFIX variable of the SET command.

When you enter @file_name.ext, SQL*Plus searches for a file with the filename and extension you specify in the current default directory. If SQL*Plus does not find such a file, SQL*Plus will search a system-dependent path to find the file. Some operating systems may not support the path search. See the Oracle installation and user's manual(s) provided for your operating system for specific information related to your operating system environment.

arg...

Represent data items you wish to pass to parameters in the script. If you enter one or more arguments, SQL*Plus substitutes the values into the parameters (&1, &2, and so forth) in the script. The first argument replaces each occurrence of &1, the second replaces each occurrence of &2, and so forth.

The @ command DEFINEs the parameters with the values of the arguments; if you run the script again in this session, you can enter new arguments or omit the arguments to use the current values.

For more information on using parameters, refer to the subsection "Substitution Variables in iSQL*Plus" under "Writing Interactive Commands".

Usage

All previous settings like COLUMN command settings stay in effect when the script starts. If the script changes any setting, then this new value stays in effect after the script has finished

In a script, you can include any command you would normally enter interactively (typically, SQL, SQL*Plus commands, or PL/SQL blocks).

An EXIT or QUIT command used in a script terminates SQL*Plus.

The @ command functions similarly to START.

If the START command is disabled (see "Disabling SQL*Plus, SQL, and PL/SQL Commands"), this will also disable the @ command. See START for information on the START command.

SQL*Plus removes the SQLTERMINATOR (a semicolon by default) before the @ command is issued. If you require a semicolon in your command, add a second SQLTERMINATOR. See the SQLTERMINATOR variable of the SET command in this chapter for more information.

Examples

To run a script named PRINTRPT with the extension SQL, enter

Keyboard icon
@PRINTRPT

To run a script named WKRPT with the extension QRY, enter

Keyboard icon
@WKRPT.QRY

You can run a script named YEAREND specified by a URL, and pass values to variables referenced in YEAREND in the usual way:

Keyboard icon
@HTTP://machine_name.domain:port/YEAREND.SQL VAL1 VAL2 @FTP://machine_name.domain:port/YEAREND.SQL VAL1 VAL2

On a web server configured to serve SQL reports, you could request SQL*Plus to execute a dynamic script by using:

Keyboard icon
@HTTP://machine_name.domain:port/SCRIPTSERVER?ENDOFYEAR VAL1 VAL2

@@ (double "at" sign)

@@url|file_name[.ext]

Runs a script. This command is almost identical to the @ ("at" sign) command. It is useful for running nested scripts because it has the additional functionality of looking for the specified script in the same path or url as the script from which it was called. Only the url form is supported in iSQL*Plus.

Terms

Refer to the following for a description of the term or clause:

url

Specifies the Uniform Resource Locator of a script to run on the specified web server. SQL*Plus supports HTTP and FTP protocols.

file_name[.ext]

Represents the nested script you wish to run. If you omit ext, SQL*Plus assumes the default command-file extension (normally SQL). For information on changing the default extension, see the SUFFIX variable of the SET command.

When you enter @@file_name.ext from within a script, SQL*Plus runs file_name.ext from the same directory as the script.

When you enter @@file_name.ext interactively, SQL*Plus runs file_name.ext from the current working directory or from the same url as the script from which it was called. If SQL*Plus does not find such a file, SQL*Plus searches a system-dependent path to find the file. Some operating systems may not support the path search. See the Oracle installation and user's manual provided for your operating system for specific information related to your operating system environment.

Usage

All previous settings like COLUMN command settings stay in effect when the script starts. If the script changes any setting, then this new value stays in effect after the script has finished

You can include in a script any command you would normally enter interactively (typically, SQL or SQL*Plus commands).

An EXIT or QUIT command used in a script terminates SQL*Plus.

The @@ command functions similarly to START.

If the START command is disabled (see "Disabling SQL*Plus, SQL, and PL/SQL Commands"), this will also disable the @@ command. For more information, see the SPOOL command.

SQL*Plus removes the SQLTERMINATOR (a semicolon by default) before the @@ command is issued. A workaround for this is to add another SQLTERMINATOR. See the SQLTERMINATOR variable of the SET command for more information.

Examples

Suppose that you have the following script named PRINTRPT:

Keyboard icon
SELECT DEPARTMENT_ID, CITY FROM EMP_DETAILS_VIEW WHERE SALARY>12000; @EMPRPT.SQL @@ WKRPT.SQL

When you START PRINTRPT and it reaches the @ command, it looks for the script named EMPRPT in the current working directory and runs it. When PRINTRPT reaches the @@ command, it looks for the script named WKRPT in the same path as PRINTRPT and runs it.

Suppose that the same script PRINTRPT was located on a web server and you ran it with START HTTP://machine_name.domain:port/PRINTRPT. When it reaches the @ command, it looks for the script named EMPRPT in the current local working directory and runs it. When PRINTRPT reaches the @@ command, it looks for the script named WKRPT in the same url as PRINTRPT, HTTP://machine_name.domain:port/WKRPT.SQL and runs it.

/ (slash)

/(slash)

Executes the SQL command or PL/SQL block currently stored in the SQL buffer.

Usage

You can enter a slash (/) at the command prompt or at a line number prompt of a multi-line command.

The slash command functions similarly to RUN, but does not list the command in the buffer on your screen.

Executing a SQL command or PL/SQL block using the slash command will not cause the current line number in the SQL buffer to change unless the command in the buffer contains an error. In that case, SQL*Plus changes the current line number to the number of the line containing the error.

Examples

Type the following SQL script:

Keyboard icon
SELECT CITY, COUNTRY_NAME FROM EMP_DETAILS_VIEW WHERE SALARY=12000;

Enter a slash (/) at the command prompt to re-execute the command in the buffer:

Keyboard icon
/ Screen icon
CITY COUNTRY_NAME ------------------------------ ---------------------------------------- Seattle United States of America Oxford United Kingdom Seattle United States of America

ACCEPT

ACCEPT is not available in iSQL*Plus.

ACC[EPT] variable [NUM[BER]|CHAR|DATE] [FOR[MAT] format] [DEF[AULT] default]
[PROMPT text|NOPR[OMPT]] [HIDE]

Reads a line of input and stores it in a given user variable.

Terms

Refer to the following list for a description of each term or clause:

variable

Represents the name of the variable in which you wish to store a value. If variable does not exist, SQL*Plus creates it.

NUM[BER]

Makes the datatype of variable the datatype NUMBER. If the reply does not match the datatype, ACCEPT gives an error message and prompts again.

CHAR

Makes the datatype of variable the datatype CHAR. The maximum CHAR length limit is 240 bytes. If a multi-byte character set is used, one CHAR may be more than one byte in size.

DATE

Makes reply a valid DATE format. If the reply is not a valid DATE format, ACCEPT gives an error message and prompts again. The datatype is CHAR.

FOR[MAT]

Specifies the input format for the reply. If the reply does not match the specified format, ACCEPT gives an error message and prompts again for a reply. The format element must be a text constant such as A10 or 9.999. See the CHANGE command in this chapter for a complete list of format elements.

Oracle date formats such as "dd/mm/yy" are valid when the datatype is DATE. DATE without a specified format defaults to the Oracle NLS_DATE_FORMAT of the current session. See the Oracle9i Database Administrator's Guide and the Oracle9i SQL Reference for information on Oracle date formats.

DEF[AULT]

Sets the default value if a reply is not given. The reply must be in the specified format if defined.

PROMPT text

Displays text on-screen before accepting the value of variable from the user.

NOPR[OMPT]

Skips a line and waits for input without displaying a prompt.

HIDE

Suppresses the display as you type the reply.

To display or reference variables, use the DEFINE command. See the DEFINE command in this chapter for more information.

Examples

To display the prompt "Password: ", place the reply in a CHAR variable named PSWD, and suppress the display, enter

Keyboard icon
ACCEPT pswd CHAR PROMPT 'Password: ' HIDE

To display the prompt "Enter weekly salary: " and place the reply in a NUMBER variable named SALARY with a default of 000.0, enter

Keyboard icon
ACCEPT salary NUMBER FORMAT '999.99' DEFAULT '000.0' - PROMPT 'Enter weekly salary: '

To display the prompt "Enter date hired: " and place the reply in a DATE variable named HIRED with the format "dd/mm/yyyy" and a default of "01/01/2001", enter

Keyboard icon
ACCEPT hired DATE FORMAT 'dd/mm/yyyy' DEFAULT '01/01/2001'- PROMPT 'Enter date hired: '

APPEND

APPEND is not available in iSQL*Plus.

A[PPEND] text

Adds specified text to the end of the current line in the SQL buffer.

Terms

Refer to the following for a description of the term or clause:

text

Represents the text to append. To separate text from the preceding characters with a space, enter two spaces between APPEND and text.

To APPEND text that ends with a semicolon, end the command with two semicolons (SQL*Plus interprets a single semicolon as an optional command terminator).

Examples

To append a comma delimiter, a space and the column name CITY to the first line of the buffer, make that line the current line by listing the line as follows:

Keyboard icon
1 Screen icon
1* SELECT DEPARTMENT_ID

Now enter APPEND:

Keyboard icon
APPEND , CITY 1 Screen icon
1* SELECT DEPARTMENT_ID, CITY

To append a semicolon to the line, enter

Keyboard icon
APPEND ;;

SQL*Plus appends the first semicolon to the line and interprets the second as the terminator for the APPEND command.

ARCHIVE LOG

ARCHIVE LOG {LIST|STOP}|{START|NEXT|ALL|integer } [TO destination]

Starts or stops automatic archiving of online redo log files, manually (explicitly) archives specified redo log files, or displays information about redo log files.

Terms

Refer to the following list for a description of each term or clause:

LIST

Requests a display that shows the range of redo log files to be archived, the current log file group's sequence number, and the current archive destination (specified by either the optional command text or by the initialization parameter LOG_ARCHIVE_DEST).

If you are using both ARCHIVELOG mode and automatic archiving, the display might appear like:

ARCHIVE LOG LIST

Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /vobs/oracle/dbs/arch
Oldest online log sequence     221
Next log sequence to archive   222
Current log sequence           222

Since the log sequence number of the current log group and the next log group to archive are the same, automatic archival has archived all log groups up to the current one.

If you are using ARCHIVELOG but have disabled automatic archiving, the last three lines might look like:

Oldest online log sequence            222
Next log sequence to archive          222
Current log sequence                  225

If you are using NOARCHIVELOG mode, the "next log sequence to archive" line is suppressed.

The log sequence increments every time the Log Writer begins to write to another redo log file group; it does not indicate the number of logs being used. Every time an online redo log file group is reused, the contents are assigned a new log sequence number.

STOP

Disables automatic archival. If the instance is still in ARCHIVELOG mode and all redo log file groups fill, database operation is suspended until a redo log file is archived (for example, until you enter the command ARCHIVE LOG NEXT or ARCHIVE LOG ALL).

START

Enables automatic archiving. Starts the background process ARCH, which performs automatic archiving as required. If ARCH is started and a filename is supplied, the filename becomes the new default archive destination. ARCH automatically starts on instance startup if the initialization parameter LOG_ARCHIVE_START is set to TRUE.

NEXT

Manually archives the next online redo log file group that has been filled, but not yet archived.

ALL

Manually archives all filled, but not yet archived, online redo log file groups.

integer

Causes archival of the online redo log file group with log sequence number n. You can specify any redo log file group that is still online. An error occurs if the log file cannot be found online or the sequence number is not valid. This option can be used to re-archive a log file group.

destination

Specifies the destination device or directory in an operating system. Specification of archive destination devices is installation-specific; see your platform-specific Oracle documentation for examples of specifying archive destinations. On many operating systems, multiple log files can be spooled to the same tape.

If not specified in the command-line, the archive destination is derived from the initialization parameter LOG_ARCHIVE_DEST. The command ARCHIVE LOG START destination causes the specified device or directory to become the new default archive destination for all future automatic or manual archives. A destination specified with any other option is a temporary destination that is in effect only for the current (manual) archive. It does not change the default archive destination for subsequent automatic archives. For information about specifying archive destinations, see your platform-specific Oracle documentation.

Usage

You must be connected to an open Oracle database as SYSOPER, or SYSDBA. For information about connecting to the database, see the CONNECT command in this chapter.

If an online redo log file group fills and none are available for reuse, database operation is suspended. The condition can be resolved by archiving a log file group.

For information about specifying archive destinations, see your platform-specific Oracle documentation.


Note::

This command applies only to the current instance. To specify archiving for a different instance or for all instances in a Parallel Server, use the SQL command ALTER SYSTEM. For more information about using SQL commands, see the Oracle9i SQL Reference.


Examples

To start up the archiver process and begin automatic archiving, using the archive destination specified in LOG_ARCHIVE_DEST, enter

Keyboard icon
ARCHIVE LOG START

To stop automatic archiving, enter

Keyboard icon
ARCHIVE LOG STOP

To archive the log file group with sequence number 1001 to the destination specified, enter

Keyboard icon
ARCHIVE LOG 1001 '/vobs/oracle/dbs/arch'

'arch' specifies the prefix of the filename on the destination device; the remainder of the filename is dependent on the initialization parameter LOG_ARCHIVE_FORMAT, which specifies the filename format for archived redo log files.

ATTRIBUTE

ATTRIBUTE [type_name.attribute_name [option ...]]

where option represents one of the following clauses:

ALI[AS] alias
CLE[AR]
FOR[MAT] format
LIKE {type_name.attribute_name|alias}
ON|OFF

Specifies display characteristics for a given attribute of an Object Type column, such as format for NUMBER data.

Also lists the current display characteristics for a single attribute or all attributes.

Terms

Enter ATTRIBUTE followed by type_name.attribute_name and no other clauses to list the current display characteristics for only the specified attribute. Enter ATTRIBUTE with no clauses to list all current attribute display characteristics.

Refer to the following list for a description of each term or clause:

type_name.attribute_name

Identifies the data item (typically the name of an attribute) within the set of attributes for a given object of Object Type, type_name.

If you select objects of the same Object Type, an ATTRIBUTE command for that type_name.attribute_name will apply to all such objects you reference in that session.

ALI[AS] alias

Assigns a specified alias to a type_name.attribute_name, which can be used to refer to the type_name.attribute_name in other ATTRIBUTE commands.

CLE[AR]

Resets the display characteristics for the attribute_name. The format specification must be a text constant such as A10 or $9,999--not a variable.

FOR[MAT] format

Specifies the display format of the column. The format specification must be a text constant such as A10 or $9,999--not a variable.

LIKE {type_name.attribute_name|alias}

Copies the display characteristics of another attribute. LIKE copies only characteristics not defined by another clause in the current ATTRIBUTE command.

ON|OFF

Controls the status of display characteristics for a column. OFF disables the characteristics for an attribute without affecting the characteristics' definition. ON reinstates the characteristics.

Usage

You can enter any number of ATTRIBUTE commands for one or more attributes. All attribute characteristics set for each attribute remain in effect for the remainder of the session, until you turn the attribute OFF, or until you use the CLEAR COLUMN command. Thus, the ATTRIBUTE commands you enter can control an attribute's display characteristics for multiple SQL SELECT commands.

When you enter multiple ATTRIBUTE commands for the same attribute, SQL*Plus applies their clauses collectively. If several ATTRIBUTE commands apply the same clause to the same attribute, the last one entered will control the output.

Examples

To make the LAST_NAME attribute of the Object Type EMPLOYEE_TYPE 20 characters wide, enter

Keyboard icon
ATTRIBUTE EMPLOYEE_TYPE.LAST_NAME FORMAT A20

To format the SALARY attribute of the Object Type EMPLOYEE_TYPE so that it shows millions of dollars, rounds to cents, uses commas to separate thousands, and displays $0.00 when a value is zero, enter

Keyboard icon
ATTRIBUTE EMPLOYEE_TYPE.SALARY FORMAT $9,999,990.99

BREAK

BRE[AK] [ON report_element [action [action]]] ...

where:

report_element

Requires the following syntax:

{column|expr|ROW|REPORT}

action

Requires the following syntax:

[SKI[P] n|[SKI[P]] PAGE][NODUP[LICATES]|DUP[LICATES]]

Specifies where changes occur in a report and the formatting action to perform, such as:

Enter BREAK with no clauses to list the current BREAK definition.

Terms

Refer to the following list for a description of each term or clause:

ON column [action [action]]

When you include action(s), specifies action(s) for SQL*Plus to take whenever a break occurs in the specified column (called the break column). (column cannot have a table or view appended to it. To achieve this, you can alias the column in the SQL statement.) A break is one of three events, a change in the value of a column or expression, the output of a row, or the end of a report

When you omit action(s), BREAK ON column suppresses printing of duplicate values in column and marks a place in the report where SQL*Plus will perform the computation you specify in a corresponding COMPUTE command.

You can specify ON column one or more times. If you specify multiple ON clauses, as in

BREAK ON DEPARTMENT_ID SKIP PAGE ON JOB_ID - 
SKIP 1 ON SALARY SKIP 1

the first ON clause represents the outermost break (in this case, ON DEPARTMENT_ID) and the last ON clause represents the innermost break (in this case, ON SALARY). SQL*Plus searches each row of output for the specified break(s), starting with the outermost break and proceeding--in the order you enter the clauses--to the innermost. In the example, SQL*Plus searches for a change in the value of DEPARTMENT_ID, then JOB_ID, then SALARY.

Next, SQL*Plus executes actions beginning with the action specified for the innermost break and proceeding in reverse order toward the outermost break (in this case, from SKIP 1 for ON SALARY toward SKIP PAGE for ON DEPARTMENT_ID). SQL*Plus executes each action up to and including the action specified for the first occurring break encountered in the initial search.

If, for example, in a given row the value of JOB_ID changes--but the values of DEPARTMENT_ID and SALARY remain the same--SQL*Plus skips two lines before printing the row (one as a result of SKIP 1 ON SALARY and one as a result of SKIP 1 ON JOB_ID).

Whenever you use ON column, you should also use an ORDER BY clause in the SQL SELECT command. Typically, the columns used in the BREAK command should appear in the same order in the ORDER BY clause (although all columns specified in the ORDER BY clause need not appear in the BREAK command). This prevents breaks from occurring at meaningless points in the report.

If the BREAK command specified earlier in this section is used, the following SELECT command produces meaningful results:

SELECT DEPARTMENT_ID, JOB_ID, SALARY, LAST_NAME
FROM EMP_DETAILS_VIEW
WHERE SALARY > 12000
ORDER BY DEPARTMENT_ID, JOB_ID, SALARY, LAST_NAME;

All rows with the same DEPARTMENT_ID print together on one page, and within that page all rows with the same JOB_ID print in groups. Within each group of jobs, those jobs with the same SALARY print in groups. Breaks in LAST_NAME cause no action because LAST_NAME does not appear in the BREAK command.

ON expr [action [action]]

When you include action(s), specifies action(s) for SQL*Plus to take when the value of the expression changes.

When you omit action(s), BREAK ON expr suppresses printing of duplicate values of expr and marks a place in the report where SQL*Plus will perform the computation you specify in a corresponding COMPUTE command.

You can use an expression involving one or more table columns or an alias assigned to a report column in a SQL SELECT or SQL*Plus COLUMN command. If you use an expression in a BREAK command, you must enter expr exactly as it appears in the SELECT command. If the expression in the SELECT command is a+b, for example, you cannot use b+a or (a+b) in a BREAK command to refer to the expression in the SELECT command.

The information given above for ON column also applies to ON expr.

ON ROW [action [action]]

When you include action(s), specifies action(s) for SQL*Plus to take when a SQL SELECT command returns a row. The ROW break becomes the innermost break regardless of where you specify it in the BREAK command. You should always specify an action when you BREAK on a row.

ON REPORT [action]

Marks a place in the report where SQL*Plus will perform the computation you specify in a corresponding COMPUTE command. Use BREAK ON REPORT in conjunction with COMPUTE to print grand totals or other "grand" computed values.

The REPORT break becomes the outermost break regardless of where you specify it in the BREAK command.

Note that SQL*Plus will not skip a page at the end of a report, so you cannot use BREAK ON REPORT SKIP PAGE.

Refer to the following list for a description of each action:

SKI[P] n

Skips n lines before printing the row where the break occurred. BREAK SKIP n does not work in SET MARKUP HTML ON mode or in iSQL*Plus unless PREFORMAT is SET ON.

[SKI[P]] PAGE

Skips the number of lines that are defined to be a page before printing the row where the break occurred. The number of lines per page can be set via the PAGESIZE clause of the SET command. Note that PAGESIZE only changes the number of lines that SQL*Plus considers to be a page. Therefore, SKIP PAGE may not always cause a physical page break, unless you have also specified NEWPAGE 0. Note also that if there is a break after the last row of data to be printed in a report, SQL*Plus will not skip the page.

NODUP[LICATES]

Prints blanks rather than the value of a break column when the value is a duplicate of the column's value in the preceding row.

DUP[LICATES]

Prints the value of a break column in every selected row.

Enter BREAK with no clauses to list the current break definition.

Usage

Each new BREAK command you enter replaces the preceding one.

To remove the BREAK command, use CLEAR BREAKS.

Examples

To produce a report that prints duplicate job values, prints the average of SALARY and inserts one blank line when the value of JOB_ID changes, and additionally prints the sum of SALARY and inserts another blank line when the value of DEPARTMENT_ID changes, you could enter the following commands. (The example selects departments 50 and 80 and the jobs of clerk and salesman only.)

Keyboard icon
BREAK ON DEPARTMENT_ID SKIP 1 ON JOB_ID SKIP 1 DUPLICATES COMPUTE SUM OF SALARY ON DEPARTMENT_ID COMPUTE AVG OF SALARY ON JOB_ID SELECT DEPARTMENT_ID, JOB_ID, LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE JOB_ID IN ('SH_CLERK', 'SA_MAN') AND DEPARTMENT_ID IN (50, 80) ORDER BY DEPARTMENT_ID, JOB_ID; Screen icon
DEPARTMENT_ID JOB_ID LAST_NAME SALARY ------------- ---------- ------------------------- ---------- 50 SH_CLERK Taylor 3200 SH_CLERK Fleaur 3100 . . . SH_CLERK Gates 2900 DEPARTMENT_ID JOB_ID LAST_NAME SALARY ------------- ---------- ------------------------- ---------- 50 SH_CLERK Perkins 2500 SH_CLERK Bell 4000 . . . SH_CLERK Grant 2600 ********** ---------- avg 3215 DEPARTMENT_ID JOB_ID LAST_NAME SALARY ------------- ---------- ------------------------- ---------- ************* ---------- sum 64300 80 SA_MAN Russell 14000 SA_MAN Partners 13500 SA_MAN Errazuriz 12000 SA_MAN Cambrault 11000 SA_MAN Zlotkey 10500 ********** ---------- avg 12200 DEPARTMENT_ID JOB_ID LAST_NAME SALARY ------------- ---------- ------------------------- ---------- ************* ---------- sum 61000 25 rows selected.

BTITLE

BTI[TLE] [printspec [text|variable] ...] [ON|OFF]

where printspec represents one or more of the following clauses used to place and format the text:

COL n

CE[NTER]

S[KIP] [n]

R[IGHT]

TAB n

BOLD

LE[FT]

FORMAT text

Places and formats a specified title at the bottom of each report page, or lists the current BTITLE definition.

For a description of the old form of BTITLE, see Appendix C, "Obsolete SQL*Plus Commands".

Terms

Refer to the TTITLE command in this chapter for information on terms and clauses in the BTITLE command syntax.

Enter BTITLE with no clauses to list the current BTITLE definition.

Usage

If you do not enter a printspec clause before the first occurrence of text, BTITLE left justifies the text. SQL*Plus interprets BTITLE in the new form if a valid printspec clause (LEFT, SKIP, COL, and so on) immediately follows the command name.

Examples

To set a bottom title with CORPORATE PLANNING DEPARTMENT on the left and a date on the right, enter

Keyboard icon
BTITLE LEFT 'CORPORATE PLANNING DEPARTMENT' - RIGHT '1 JAN 2001'

To set a bottom title with CONFIDENTIAL in column 50, followed by six spaces and a date, enter

Keyboard icon
BTITLE COL 50 'CONFIDENTIAL' TAB 6 '1 JAN 2001'

CHANGE

CHANGE is not available in iSQL*Plus.

C[HANGE] sepchar old [sepchar [new [sepchar]]]

Changes the first occurrence of the specified text on the current line in the buffer.

Terms

Refer to the following list for a description of each term or clause:

sepchar

Represents any non-alphanumeric character such as "/" or "!". Use a sepchar that does not appear in old or new.

old

Represents the text you wish to change. CHANGE ignores case in searching for old. For example,

CHANGE /aq/aw

will find the first occurrence of "aq", "AQ", "aQ", or "Aq" and change it to "aw". SQL*Plus inserts the new text exactly as you specify it.

If old is prefixed with "...", it matches everything up to and including the first occurrence of old. If it is suffixed with "...", it matches the first occurrence of old and everything that follows on that line. If it contains an embedded "...", it matches everything from the preceding part of old through the following part of old.

new

Represents the text with which you wish to replace old. If you omit new and, optionally, the second and third sepchars, CHANGE deletes old from the current line of the buffer.

Usage

CHANGE changes the first occurrence of the existing specified text on the current line of the buffer to the new specified text. The current line is marked with an asterisk (*) in the LIST output.

You can also use CHANGE to modify a line in the buffer that has generated an Oracle error. SQL*Plus sets the buffer's current line to the line containing the error so that you can make modifications.

To reenter an entire line, you can type the line number followed by the new contents of the line. If you specify a line number larger than the number of lines in the buffer and follow the number with text, SQL*Plus adds the text in a new line at the end of the buffer. If you specify zero ("0") for the line number and follow the zero with text, SQL*Plus inserts the line at the beginning of the buffer (that line becomes line 1).

Examples

Enter 3 so the current line of the buffer contains the following text:

Keyboard icon
3 Screen icon
3* WHERE JOB_ID IS IN ('CLERK', 'SA_MAN')

Enter the following command:

Keyboard icon
CHANGE /CLERK/SH_CLERK/

The text in the buffer changes as follows:

Screen icon
3* WHERE JOB_ID IN ('SH_CLERK', 'SA_MAN')

Or enter the following command:

Keyboard icon
CHANGE /'CLERK',... /'SH_CLERK'/

The original line changes to

Screen icon
3* WHERE JOB_ID IS IN ('SH_CLERK')

Or enter the following command:

Keyboard icon
CHANGE /(...)/('SA_MAN')/

The original line changes to

Screen icon
3* WHERE JOB_ID IS IN ('SA_MAN')

You can replace the contents of an entire line using the line number. This entry

Keyboard icon
3 WHERE JOB_ID IS IN ('SH_CLERK')

causes the second line of the buffer to be replaced with

WHERE JOB_ID IS IN ('SH_CLERK')

Note that entering a line number followed by a string will replace the line regardless of what text follows the line number. For example,

Keyboard icon
2 CHANGE/OLD/NEW/

will change the second line of the buffer to be

Screen icon
2* C/OLD/NEW/

CLEAR

CL[EAR] option ...

where option represents one of the following clauses:

BRE[AKS]
BUFF[ER]
COL[UMNS]
COMP[UTES]
SCR[EEN]
SQL
TIMI[NG]

Resets or erases the current value or setting for the specified option.

Terms

Refer to the following list for a description of each term or clause:

BRE[AKS]

Removes the break definition set by the BREAK command.

BUFF[ER]

Clears text from the buffer. CLEAR BUFFER has the same effect as CLEAR SQL, unless you are using multiple buffers (see the SET BUFFER command in Appendix C, "Obsolete SQL*Plus Commands").

COL[UMNS]

Resets column display attributes set by the COLUMN command to default settings for all columns. To reset display attributes for a single column, use the CLEAR clause of the COLUMN command. CLEAR COLUMNS also clears the ATTRIBUTEs for that column.

COMP[UTES]

Removes all COMPUTE definitions set by the COMPUTE command.

SCR[EEN]

Clears your screen.

CLEAR SCREEN is not available in iSQL*Plus.

SQL

Clears the text from SQL buffer. CLEAR SQL has the same effect as CLEAR BUFFER, unless you are using multiple buffers (see the SET BUFFER command in Appendix C, "Obsolete SQL*Plus Commands").

TIMI[NG]

Deletes all timers created by the TIMING command.

Examples

To clear breaks, enter

Keyboard icon
CLEAR BREAKS

To clear column definitions, enter

Keyboard icon
CLEAR COLUMNS

COLUMN

COL[UMN] [{column|expr} [option ...]]

where option represents one of the following clauses:

ALI[AS] alias
CLE[AR]
ENTMAP {ON|OFF}
FOLD_A[FTER]
FOLD_B[EFORE]
FOR[MAT] format
HEA[DING] text
JUS[TIFY] {L[EFT]|C[ENTER]|C[ENTRE]|R[IGHT]}
LIKE {expr|alias}
NEWL[INE]
NEW_V[ALUE] variable
NOPRI[NT]|PRI[NT]
NUL[L] text
OLD_V[ALUE] variable
ON|OFF
WRA[PPED]|WOR[D_WRAPPED]|TRU[NCATED]

Specifies display attributes for a given column, such as

Also lists the current display attributes for a single column or all columns.

Terms

Enter COLUMN followed by column or expr and no other clauses to list the current display attributes for only the specified column or expression. Enter COLUMN with no clauses to list all current column display attributes.

Refer to the following list for a description of each term or clause:

{column|expr}

Identifies the data item (typically, the name of a column) in a SQL SELECT command to which the column command refers. If you use an expression in a COLUMN command, you must enter expr exactly as it appears in the SELECT command. If the expression in the SELECT command is a+b, for example, you cannot use b+a or (a+b) in a COLUMN command to refer to the expression in the SELECT command.

If you select columns with the same name from different tables, a COLUMN command for that column name will apply to both columns. That is, a COLUMN command for the column LAST_NAME applies to all columns named LAST_NAME that you reference in this session. COLUMN ignores table name prefixes in SELECT commands. Also, spaces are ignored unless the name is placed in double quotes.

To format the columns differently, assign a unique alias to each column within the SELECT command itself (do not use the ALIAS clause of the COLUMN command) and enter a COLUMN command for each column's alias.

ALI[AS] alias

Assigns a specified alias to a column, which can be used to refer to the column in BREAK, COMPUTE, and other COLUMN commands.

CLE[AR]

Resets the display attributes for the column to default values.

To reset the attributes for all columns, use the CLEAR COLUMNS command. CLEAR COLUMNS also clears the ATTRIBUTEs for that column.

ENTMAP {ON|OFF}

Allows entity mapping to be turned on or off for selected columns in HTML output. This feature allows you to include, for example, HTML hyperlinks in a column of data, while still mapping entities in other columns of the same report. By turning entity mapping off for a column containing HTML hyperlinks, the HTML anchor tag delimiters, <, >, " and &, are correctly interpreted in the report. Otherwise they would be replaced with their respective entities, &lt;, &gt;, &quot; and &amp;, preventing web browsers from correctly interpreting the HTML.

Entities in the column heading and any COMPUTE labels or output appearing in the column are mapped or not mapped according to the value of ENTMAP for the column.

The default setting for COLUMN ENTMAP is the current setting of the MARKUP HTML ENTMAP option. For more information about the MARKUP HTML ENTMAP option, see SET "MARKUP Options" and SET later this Chapter.

FOLD_A[FTER]

Inserts a carriage return after the column heading and after each row in the column. SQL*Plus does not insert an extra carriage return after the last column in the SELECT list.

FOLD_B[EFORE]

Inserts a carriage return before the column heading and before each row of the column. SQL*Plus does not insert an extra carriage return before the first column in the SELECT list.

FOR[MAT] format

Specifies the display format of the column. The format specification must be a text constant such as A10 or $9,999--not a variable.

Character Columns The default width of CHAR, NCHAR, VARCHAR2 (VARCHAR) and NVARCHAR2 (NCHAR VARYING) columns is the width of the column in the database. SQL*Plus formats these datatypes left-justified. If a value does not fit within the column width, SQL*Plus wraps or truncates the character string depending on the setting of SET WRAP.

A LONG, CLOB, NCLOB or XMLType column's width defaults to the value of SET LONGCHUNKSIZE or SET LONG, whichever one is smaller.

To change the width of a datatype to n, use FORMAT An. (A stands for alphanumeric.) If you specify a width shorter than the column heading, SQL*Plus truncates the heading.

DATE Columns The default width and format of unformatted DATE columns in SQL*Plus is derived from the NLS parameters in effect. Otherwise, the default width is A9. In Oracle9i, the NLS parameters may be set in your database parameter file or may be environment variables or an equivalent platform-specific mechanism. They may also be specified for each session with the ALTER SESSION command. (See the documentation for Oracle9i for a complete description of the NLS parameters).

You can change the format of any DATE column using the SQL function TO_CHAR in your SQL SELECT statement. You may also wish to use an explicit COLUMN FORMAT command to adjust the column width.

When you use SQL functions like TO_CHAR, Oracle automatically allows for a very wide column.

To change the width of a DATE column to n, use the COLUMN command with FORMAT An. If you specify a width shorter than the column heading, the heading is truncated.

NUMBER Columns To change a NUMBER column's width, use FORMAT followed by an element as specified in Table 13-1.

Table 13-1 Number Formats
Element Examples Description

9

9999

Number of "9"s specifies number of significant digits returned. Blanks are displayed for leading zeroes. A zero (0) is displayed for a value of zero.

0

0999
9990

Displays a leading zero or a value of zero in this position as 0.

$

$9999

Prefixes value with dollar sign.

B

B9999

Displays a zero value as blank, regardless of "0"s in the format model.

MI

9999MI

Displays "-" after a negative value. For a positive value, a trailing space is displayed.

S

S9999

Returns "+" for positive values and "-" for negative values in this position.

PR

9999PR

Displays a negative value in <angle brackets>. For a positive value, a leading and trailing space is displayed.

D

99D99

Displays the decimal character in this position, separating the integral and fractional parts of a number.

G

9G999

Displays the group separator in this position.

C

C999

Displays the ISO currency symbol in this position.

L

L999

Displays the local currency symbol in this position.

, (comma)

9,999

Displays a comma in this position.

. (period)

99.99

Displays a period (decimal point) in this position, separating the integral and fractional parts of a number.

V

999V99

Multiplies value by 10n, where n is number of "9"s after "V".

EEEE

9.999EEEE

Displays value in scientific notation (format must contain exactly four "E"s).

RN or rn

RN

Displays upper- or lowercase Roman numerals. Value can be an integer between 1 and 3999.

DATE

DATE

Displays value as a date in MM/DD/YY format; used to format NUMBER columns that represent Julian dates.

The MI and PR format elements can only appear in the last position of a number format model. The S format element can only appear in the first or last position.

If a number format model does not contain the MI, S or PR format elements, negative return values automatically contain a leading negative sign and positive values automatically contain a leading space.

A number format model can contain only a single decimal character (D) or period (.), but it can contain multiple group separators (G) or commas (,). A group separator or comma cannot appear to the right of a decimal character or period in a number format model.

SQL*Plus formats NUMBER data right-justified. A NUMBER column's width equals the width of the heading or the width of the FORMAT plus one space for the sign, whichever is greater. If you do not explicitly use FORMAT, then the column's width will always be at least the value of SET NUMWIDTH.

SQL*Plus may round your NUMBER data to fit your format or field width.

If a value cannot fit within the column width, SQL*Plus indicates overflow by displaying a pound sign (#) in place of each digit the width allows.

If a positive value is extremely large and a numeric overflow occurs when rounding a number, then the infinity sign (~) replaces the value. Likewise, if a negative value is extremely small and a numeric overflow occurs when rounding a number, then the negative infinity sign replaces the value (-~).

HEA[DING] text

Defines a column heading. If you do not use a HEADING clause, the column's heading defaults to column or expr. If text contains blanks or punctuation characters, you must enclose it with single or double quotes. Each occurrence of the HEADSEP character (by default, "|") begins a new line.

For example,

COLUMN LAST_NAME HEADING 'Employee |Name'

would produce a two-line column heading. See the HEADSEP variable of the SET command in this chapter for information on changing the HEADSEP character.

JUS[TIFY] {L[EFT]|C[ENTER]|C[ENTRE]|R[IGHT]}

Aligns the heading. If you do not use a JUSTIFY clause, headings for NUMBER columns default to RIGHT and headings for other column types default to LEFT.

LIKE {expr|alias}

Copies the display attributes of another column or expression (whose attributes you have already defined with another COLUMN command). LIKE copies only attributes not defined by another clause in the current COLUMN command.

NEWL[INE]

Starts a new line before displaying the column's value. NEWLINE has the same effect as FOLD_BEFORE.

NEW_V[ALUE] variable

Specifies a variable to hold a column value. You can reference the variable in TTITLE commands. Use NEW_VALUE to display column values or the date in the top title. You must include the column in a BREAK command with the SKIP PAGE action. The variable name cannot contain a pound sign (#).

NEW_VALUE is useful for master/detail reports in which there is a new master record for each page. For master/detail reporting, you must also include the column in the ORDER BY clause. See the example at the end of this command description.

For information on displaying a column value in the bottom title, see COLUMN OLD_VALUE. For more information on referencing variables in titles, see the TTITLE command later in this chapter. For information on formatting and valid format models, see COLUMN FORMAT command.

NOPRI[NT]|PRI[NT]

Controls the printing of the column (the column heading and all the selected values). NOPRINT turns off the screen output and printing of the column. PRINT turns the printing of the column on.

NUL[L] text

Controls the text SQL*Plus displays for null values in the given column. The default is a white space. SET NULL controls the text displayed for all null values for all columns, unless overridden for a specific column by the NULL clause of the COLUMN command. When a NULL value is SELECTed, a variable's type will always become CHAR so the SET NULL text can be stored in it.

OLD_V[ALUE] variable

Specifies a variable to hold a column value. You can reference the variable in BTITLE commands. Use OLD_VALUE to display column values in the bottom title. You must include the column in a BREAK command with the SKIP PAGE action.

OLD_VALUE is useful for master/detail reports in which there is a new master record for each page. For master/detail reporting, you must also include the column in the ORDER BY clause.

For information on displaying a column value in the top title, see COLUMN NEW_VALUE. For more information on referencing variables in titles, see the TTITLE command later in this chapter.

ON|OFF

Controls the status of display attributes for a column. OFF disables the attributes for a column without affecting the attributes' definition. ON reinstates the attributes.

WRA[PPED]|WOR[D_WRAPPED]|TRU[NCATED]

Specifies how SQL*Plus will treat a datatype or DATE string that is too wide for a column. WRAPPED wraps the string within the column bounds, beginning new lines when required. When WORD_WRAP is enabled, SQL*Plus left justifies each new line, skipping all leading whitespace (for example, returns, newline characters, tabs and spaces), including embedded newline characters. Embedded whitespace not on a line boundary is not skipped. TRUNCATED truncates the string at the end of the first line of display.

Usage

You can enter any number of COLUMN commands for one or more columns. All column attributes set for each column remain in effect for the remainder of the session, until you turn the column OFF, or until you use the CLEAR COLUMN command. Thus, the COLUMN commands you enter can control a column's display attributes for multiple SQL SELECT commands.

When you enter multiple COLUMN commands for the same column, SQL*Plus applies their clauses collectively. If several COLUMN commands apply the same clause to the same column, the last one entered will control the output.

Examples

To make the LAST_NAME column 20 characters wide and display EMPLOYEE NAME on two lines as the column heading, enter

Keyboard icon
COLUMN LAST_NAME FORMAT A20 HEADING 'EMPLOYEE|NAME'

To format the SALARY column so that it shows millions of dollars, rounds to cents, uses commas to separate thousands, and displays $0.00 when a value is zero, enter

Keyboard icon
COLUMN SALARY FORMAT $9,999,990.99

To assign the alias NET to a column containing a long expression, to display the result in a dollar format, and to display <NULL> for null values, you might enter


Keyboard icon
COLUMN SALARY+COMMISSION_PCT+BONUS-EXPENSES-INS-TAX ALIAS NET COLUMN NET FORMAT $9,999,999.99 NULL '<NULL>'

Note that the example divides this column specification into two commands. The first defines the alias NET, and the second uses NET to define the format.

Also note that in the first command you must enter the expression exactly as you enter it in the SELECT command. Otherwise, SQL*Plus cannot match the COLUMN command to the appropriate column.

To wrap long values in a column named REMARKS, you can enter

Keyboard icon
COLUMN REMARKS FORMAT A20 WRAP Screen icon
CUSTOMER DATE QUANTITY REMARKS ---------- --------- -------- -------------------- 123 25-AUG-2001 144 This order must be s hipped by air freigh t to ORD

If you replace WRAP with WORD_WRAP, REMARKS looks like this:

CUSTOMER   DATE        QUANTITY REMARKS
---------- ---------   -------- ---------------------
123        25-AUG-2001      144 This order must be
                                shipped by air freight
                                to ORD

If you specify TRUNCATE, REMARKS looks like this:

CUSTOMER   DATE        QUANTITY REMARKS
---------- ---------   -------- --------------------
123        25-AUG-2001      144 This order must be s

In order to print the current date and the name of each job in the top title, enter the following. Use the EMPLOYEES table of the HR schema in this case instead of EMP_DETAILS_VIEW as you have used up to now. (For details on creating a date variable, see "Displaying the Current Date in Titles" under "Defining Page and Report Titles and Dimensions".)

Keyboard icon
COLUMN JOB_ID NOPRINT NEW_VALUE JOBVAR COLUMN TODAY NOPRINT NEW_VALUE DATEVAR BREAK ON JOB_ID SKIP PAGE ON TODAY TTITLE CENTER 'Job Report' RIGHT DATEVAR SKIP 2 - LEFT 'Job: ' JOBVAR SKIP 2 SELECT TO_CHAR(SYSDATE, 'MM/DD/YYYY') TODAY, LAST_NAME, JOB_ID, MANAGER_ID, HIRE_DATE, SALARY, DEPARTMENT_ID FROM EMPLOYEES WHERE JOB_ID IN ('MK_MAN', 'SA_MAN') ORDER BY JOB_ID, LAST_NAME;

Your two page report would look similar to the following report, with "Job Report" centered within your current linesize:

Screen icon
Job Report 04/19/01 Job: MK_MAN LAST NAME MANAGER_ID HIRE_DATE SALARY DEPARTMENT_ID -------------------- ---------- --------- -------------- ------------- Hartstein 100 17-FEB-96 $13,000.00 20 -------------- $13,000.00 Job Report 04/19/01 Job: SA_MAN LAST NAME MANAGER_ID HIRE_DATE SALARY DEPARTMENT_ID -------------------- ---------- --------- -------------- ------------- Errazuriz 100 10-MAR-97 $12,000.00 80 Zlotkey 100 29-JAN-00 $10,500.00 80 Cambrault 100 15-OCT-99 $11,000.00 80 Russell 100 01-OCT-96 $14,000.00 80 Partners 100 05-JAN-97 $13,500.00 80 -------------- Job Report 04/19/01 Job: SA_MAN LAST NAME MANAGER_ID HIRE_DATE SALARY DEPARTMENT_ID -------------------- ---------- --------- -------------- ------------- $12,200.00 6 rows selected.

To change the default format of DATE columns to 'YYYY-MM-DD', you can enter

Keyboard icon
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'; Screen icon
Session altered.

To display the change, enter a SELECT statement, such as:

Keyboard icon
SELECT HIRE_DATE FROM EMPLOYEES WHERE EMPLOYEE_ID = 206; Screen icon
Job Report 04/19/01 Job: SA_MAN HIRE_DATE ---------- 1994-06-07

See the Oracle9i SQL Reference for information on the ALTER SESSION command.

Note that in a SELECT statement, some SQL calculations or functions, such as TO_CHAR, may cause a column to be very wide. In such cases, use the FORMAT option to alter the column width.

COMPUTE

COMP[UTE] [function [LAB[EL] text] ...
OF {expr|column|alias} ...
ON {expr|column|alias|REPORT|ROW} ...]

Calculates and prints summary lines, using various standard computations, on subsets of selected rows. It also lists all COMPUTE definitions. For details on how to create summaries, see "Clarifying Your Report with Spacing and Summary Lines".

Terms

Refer to the following list for a description of each term or clause:

function ...

Represents one of the functions listed in Table 13-2. If you specify more than one function, use spaces to separate the functions.

COMPUTE command functions are always executed in the sequence AVG, COUNT, MINIMUM, MAXIMUM, NUMBER, SUM, STD, VARIANCE, regardless of their order in the COMPUTE command.

Table 13-2 COMPUTE Functions
Function Computes Applies to Datatypes
AVG

Average of non-null values

NUMBER

COU[NT]

Count of non-null values

all types

MIN[IMUM]

Minimum value

NUMBER, CHAR, NCHAR, VARCHAR2 (VARCHAR), NVARCHAR2 (NCHAR VARYING)

MAX[IMUM]

Maximum value

NUMBER, CHAR, NCHAR, VARCHAR2 (VARCHAR), NVARCHAR2 (NCHAR VARYING)

NUM[BER]

Count of rows

all types

SUM

Sum of non-null values

NUMBER

STD

Standard deviation of non-null values

NUMBER

VAR[IANCE]

Variance of non-null values

NUMBER

LAB[EL] text

Defines the label to be printed for the computed value. If no LABEL clause is used, text defaults to the unabbreviated function keyword. You must place single quotes around text containing spaces or punctuation. The label prints left justified and truncates to the column width or linesize, whichever is smaller. The maximum label length is 500 characters.

The label for the computed value appears in the break column specified. To suppress the label, use the NOPRINT option of the COLUMN command on the break column.

If you repeat a function in a COMPUTE command, SQL*Plus issues a warning and uses the first occurrence of the function.

With ON REPORT and ON ROW computations, the label appears in the first column listed in the SELECT statement. The label can be suppressed by using a NOPRINT column first in the SELECT statement. When you compute a function of the first column in the SELECT statement ON REPORT or ON ROW, then the computed value appears in the first column and the label is not displayed. To see the label, select a dummy column first in the SELECT list.

OF {expr|column|alias} ...

In the OF clause, you can refer to an expression or function reference in the SELECT statement by placing the expression or function reference in double quotes. Column names and aliases do not need quotes.

ON {expr|column|alias|REPORT|ROW} ...

Specifies the event SQL*Plus will use as a break.(column cannot have a table or view appended to it. To achieve this, you can alias the column in the SQL statement.) COMPUTE prints the computed value and restarts the computation when the event occurs (that is, when the value of the expression changes, a new ROW is fetched, or the end of the report is reached).

If multiple COMPUTE commands reference the same column in the ON clause, only the last COMPUTE command applies.

To reference a SQL SELECT expression or function reference in an ON clause, place the expression or function reference in quotes. Column names and aliases do not need quotes.

Enter COMPUTE without clauses to list all COMPUTE definitions.

Usage

In order for the computations to occur, the following conditions must all be true:

To remove all COMPUTE definitions, use the CLEAR COMPUTES command.

Note that if you use the NOPRINT option for the column on which the COMPUTE is being performed, the COMPUTE result is also suppressed.

Examples

To subtotal the salary for the "account manager", AC_MGR, and "salesman", SA_MAN, job classifications with a compute label of "TOTAL", enter

Keyboard icon
BREAK ON JOB_ID SKIP 1; COMPUTE SUM LABEL 'TOTAL' OF SALARY ON JOB_ID; SELECT JOB_ID, LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE JOB_ID IN ('AC_MGR', 'SA_MAN') ORDER BY JOB_ID, SALARY; Screen icon
JOB_ID LAST_NAME SALARY ---------- ------------------------- ---------- AC_MGR Higgins 12000 ********** ---------- TOTAL 12000 SA_MAN Zlotkey 10500 Cambrault 11000 Errazuriz 12000 Partners 13500 Russell 14000 ********** ---------- TOTAL 61000 6 rows selected.

To calculate the total of salaries greater than 12,000 on a report, enter

Keyboard icon
COMPUTE SUM OF SALARY ON REPORT BREAK ON REPORT COLUMN DUMMY HEADING '' SELECT ' ' DUMMY, SALARY, EMPLOYEE_ID FROM EMP_DETAILS_VIEW WHERE SALARY > 12000 ORDER BY SALARY; Screen icon
SALARY EMPLOYEE_ID --- ---------- ----------- 13000 201 13500 146 14000 145 17000 101 17000 102 24000 100 ---------- sum 98500 6 rows selected.

To calculate the average and maximum salary for the executive and accounting departments, enter

Keyboard icon
BREAK ON DEPARTMENT_NAME SKIP 1 COMPUTE AVG LABEL 'Dept Average' - MAX LABEL 'Dept Maximum' - OF SALARY ON DEPARTMENT_NAME SELECT DEPARTMENT_NAME, LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE DEPARTMENT_NAME IN ('Executive', 'Accounting') ORDER BY DEPARTMENT_NAME; Screen icon
DEPARTMENT_NAME LAST_NAME SALARY ------------------------------ ------------------------- ---------- Accounting Higgins 12000 Gietz 8300 ****************************** ---------- Dept Average 10150 Dept Maximum 12000 Executive King 24000 Kochhar 17000 De Haan 17000 ****************************** ---------- Dept Average 19333.3333 Dept Maximum 24000

To sum salaries for departments <= 20 without printing the compute label, enter

Keyboard icon
COLUMN DUMMY NOPRINT COMPUTE SUM OF SALARY ON DUMMY BREAK ON DUMMY SKIP 1 SELECT DEPARTMENT_ID DUMMY, DEPARTMENT_ID, LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE DEPARTMENT_ID <= 20 ORDER BY DEPARTMENT_ID; Screen icon
DEPARTMENT_ID LAST_NAME SALARY ------------- ------------------------- ---------- 10 Whalen 4400 ---------- 4400 20 Hartstein 13000 20 Fay 6000 ---------- 19000

To total the salary at the end of the report without printing the compute label, enter

Keyboard icon
COLUMN DUMMY NOPRINT COMPUTE SUM OF SALARY ON DUMMY BREAK ON DUMMY SELECT NULL DUMMY, DEPARTMENT_ID, LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE DEPARTMENT_ID <= 30 ORDER BY DEPARTMENT_ID; Screen icon
DEPARTMENT_ID LAST_NAME SALARY ------------- ------------------------- ---------- 10 Whalen 4400 20 Hartstein 13000 20 Fay 6000 30 Raphaely 11000 30 Khoo 3100 30 Baida 2900 30 Tobias 2800 30 Himuro 2600 30 Colmenares 2500 ---------- 48300 9 rows selected.

CONNECT

CONN[ECT] { logon | / } [AS {SYSOPER|SYSDBA}]

where logon requires the following syntax:

username/password[@connect_identifier]

Connects a given username to Oracle. In iSQL*Plus you must always include your username and password in a CONNECT command as iSQL*Plus does not prompt for a missing password. CONNECT does not reprompt for username or password if the initial connection does not succeed.

Terms

Refer to the following list for a description of each term or clause:

username/password

The username and password with which you wish to connect to Oracle. If you omit username and password, SQL*Plus prompts you for them. If you enter a slash (/) or simply enter Return to the prompt for username, SQL*Plus logs you in using a default logon (see "/ (slash)").

If you omit only password, SQL*Plus prompts you for password. When prompting, SQL*Plus does not display password on your terminal screen. See the PASSWORD command for information about changing your password in SQL*Plus, and see "Changing your Password" for information about changing passwords in iSQL*Plus.

connect_identifier

An Oracle Net connect identifier. The exact syntax depends on the Oracle Net communications protocol your Oracle installation uses. For more information, refer to the Oracle Net manual for your protocol or contact your DBA. SQL*Plus does not prompt for a service name, but uses your default database if you do not include a connect identifier.

/ (slash)

Represents a default logon using operating system authentication. You cannot enter a connect_identifier if you use a default logon. In a default logon, SQL*Plus typically attempts to log you in using the username OPS$name, where name is your operating system username. See the Oracle9i Database Administrator's Guide for information about operating system authentication.

AS {SYSOPER|SYSDBA}

The AS clause allows privileged connections by users who have been granted SYSOPER or SYSDBA system privileges. You can use either of these privileged connections with the default logon, /. For information about system privileges, see the Oracle9i Database Administrator's Guide.

Usage

CONNECT commits the current transaction to the database, disconnects the current username from Oracle, and reconnects with the specified username.

If you log on or connect as a user whose account has expired, SQL*Plus prompts you to change your password before you can connect.

If an account is locked, a message is displayed and connection into that account (as that user) is not permitted until the account is unlocked by your DBA.

For more information about user account management, refer to the CREATE USER, ALTER USER and the CREATE PROFILE commands in the Oracle9i SQL Reference.

Examples

To connect across Oracle Net with username HR and password HR to the database known by the Oracle Net alias as FLEETDB, enter

Keyboard icon
CONNECT HR/your_password@FLEETDB

To connect as user HR, letting SQL*Plus prompt you for the password, enter

Keyboard icon
CONNECT HR

For more information about setting up your password file, refer to the Oracle9i Database Administrator's Guide.

To use a password file to connect to an instance on the current node as a privileged user named HR with the password HR, enter

Keyboard icon
CONNECT HR/your_password AS SYSDBA

To connect to an instance on the current node as a privileged default user, enter

Keyboard icon
CONNECT / AS SYSDBA

In the last two examples, your default schema becomes SYS.

COPY

The COPY command is not being enhanced to handle datatypes or features introduced with, or after Oracle8. The COPY command is likely to be made obsolete in a future release. For COPY command details and syntax, see Appendix B, "SQL*Plus COPY Command".

DEFINE

DEF[INE] [variable]|[variable = text]

Specifies a user variable and assigns a CHAR value to it, or lists the value and variable type of a single variable or all variables.

Terms

Refer to the following list for a description of each term or clause:

variable

Represents the user variable whose value you wish to assign or list.

text

Represents the CHAR value you wish to assign to variable. Enclose text in single quotes if it contains punctuation or blanks.

variable = text

Defines (names) a user variable and assigns it a CHAR value.

Enter DEFINE followed by variable to list the value and type of variable. Enter DEFINE with no clauses to list the values and types of all user variables.

Usage

Defined variables retain their values until one of the following events occurs:

Whenever you run a stored query or script, SQL*Plus substitutes the value of variable for each substitution variable referencing variable (in the form &variable or &&variable). SQL*Plus will not prompt you for the value of variable in this session until you UNDEFINE variable.

Note that you can use DEFINE to define the variable, _EDITOR, which establishes the host system editor invoked by the SQL*Plus EDIT command.

If you continue the value of a defined variable on multiple lines (using the SQL*Plus command continuation character), SQL*Plus replaces each continuation character and carriage return you enter with a space in the resulting variable. For example, SQL*Plus interprets

DEFINE TEXT = 'ONE-
TWO-
THREE'

as

DEFINE TEXT = 'ONE TWO THREE'

You should avoid defining variables with names that may be identical to values that you will pass to them, as unexpected results can occur. If a value supplied for a defined variable matches a variable name, then the contents of the matching variable are used instead of the supplied value.

Some variables are predefined when SQL*Plus starts. Enter DEFINE to see their definitions.

Examples

To assign the value MANAGER to the variable POS, type:

Keyboard icon
DEFINE POS = MANAGER

If you execute a command that contains a reference to &POS, SQL*Plus will substitute the value MANAGER for &POS and will not prompt you for a POS value.

To assign the CHAR value 20 to the variable DEPARTMENT_ID, type:

Keyboard icon
DEFINE DEPARTMENT_ID = 20

Even though you enter the number 20, SQL*Plus assigns a CHAR value to DEPARTMENT_ID consisting of two characters, 2 and 0.

To list the definition of DEPARTMENT_ID, enter

Keyboard icon
DEFINE DEPARTMENT_ID Screen icon
DEFINE DEPARTMENT_ID = "20" (CHAR)

This result shows that the value of DEPARTMENT_ID is 20.

DEL

DEL is not available in iSQL*Plus.

DEL [n|n m|n *|n LAST|*|* n|* LAST|LAST]

Deletes one or more lines of the buffer.

Terms

Refer to the following list for a description of each term or clause:

n

Deletes line n.

n m

Deletes lines n through m.

n *

Deletes line n through the current line.

n LAST

Deletes line n through the last line.

*

Deletes the current line.

* n

Deletes the current line through line n.

* LAST

Deletes the current line through the last line.

LAST

Deletes the last line.

Enter DEL with no clauses to delete the current line of the buffer.

Usage

DEL makes the following line of the buffer (if any) the current line. You can enter DEL several times to delete several consecutive lines.


Note:

DEL is a SQL*Plus command and DELETE is a SQL command. For more information about the SQL DELETE command, see the Oracle9i SQL Reference.


Examples

Assume the SQL buffer contains the following query:

Keyboard icon
SELECT LAST_NAME, DEPARTMENT_ID FROM EMP_DETAILS_VIEW WHERE JOB_ID = 'SA_MAN' ORDER BY DEPARTMENT_ID;

To make the line containing the WHERE clause the current line, you could enter

Keyboard icon
LIST 3 Screen icon
3* WHERE JOB_ID = 'SA_MAN'

followed by

Keyboard icon
DEL

The SQL buffer now contains the following lines:

SELECT LAST_NAME, DEPARTMENT_ID
FROM EMP_DETAILS_VIEW
ORDER BY DEPARTMENT_ID

To delete the third line of the buffer, enter

Keyboard icon
DEL 3

The SQL buffer now contains the following lines:

Screen icon
SELECT LAST_NAME, DEPARTMENT_ID FROM EMP_DETAILS_VIEW

DESCRIBE

DESC[RIBE] {[schema.]object[@connect_identifier]}

Lists the column definitions for the specified table, view, or synonym, or the specifications for the specified function or procedure.

Terms

Refer to the following list for a description of each term or clause:

schema

Represents the schema where the object resides. If you omit schema, SQL*Plus assumes you own object.

object

Represents the table, view, type, procedure, function, package or synonym you wish to describe.

@connect_identifier

Consists of the database link name corresponding to the database where object exists. For more information on which privileges allow access to another table in a different schema, refer to the Oracle9i SQL Reference.

Usage

The description for tables, views, types and synonyms contains the following information:

When you do a DESCRIBE, VARCHAR columns are returned with a type of VARCHAR2.

The DESCRIBE command allows you to describe objects recursively to the depth level set in the SET DESCRIBE command. You can also display the line number and indentation of the attribute or column name when an object contains multiple object types. For more information, see the SET command later in this chapter.

To control the width of the data displayed, use the SET LINESIZE command.

Columns output for the DESCRIBE command are typically allocated a proportion of the linesize currently specified. Decreasing or increasing the linesize with the SET LINESIZE command usually makes each column proportionally smaller or larger. This may give unexpected text wrapping in your display. For more information, see the SET command later in this chapter.

The description for functions and procedures contains the following information:

Examples

To describe the view EMP_DETAILS_VIEW, enter

Keyboard icon
DESCRIBE EMP_DETAILS_VIEW Screen icon
Name Null? Type ----------------------------------------- -------- ---------------------------- EMPLOYEE_ID NOT NULL NUMBER(6) JOB_ID NOT NULL VARCHAR2(10) MANAGER_ID NUMBER(6) DEPARTMENT_ID NUMBER(4) LOCATION_ID NUMBER(4) COUNTRY_ID CHAR(2) FIRST_NAME VARCHAR2(20) LAST_NAME NOT NULL VARCHAR2(25) SALARY NUMBER(8,2) COMMISSION_PCT NUMBER(2,2) DEPARTMENT_NAME NOT NULL VARCHAR2(30) JOB_TITLE NOT NULL VARCHAR2(35) CITY NOT NULL VARCHAR2(30) STATE_PROVINCE VARCHAR2(25) COUNTRY_NAME VARCHAR2(40) REGION_NAME VARCHAR2(25)

To describe a procedure called CUSTOMER_LOOKUP, enter

Keyboard icon
DESCRIBE customer_lookup Screen icon
PROCEDURE customer_lookup Argument Name Type In/Out Default? ---------------------- -------- -------- --------- CUST_ID NUMBER IN CUST_NAME VARCHAR2 OUT

To create and describe the package APACK that contains the procedures aproc and bproc, enter

Keyboard icon
CREATE PACKAGE apack AS PROCEDURE aproc(P1 CHAR, P2 NUMBER); PROCEDURE bproc(P1 CHAR, P2 NUMBER); END apack; / Screen icon
Package created. Keyboard icon
DESCRIBE apack Screen icon
PROCEDURE APROC Argument Name Type In/Out Default? ------------------------------ ----------------------- ------ -------- P1 CHAR IN P2 NUMBER IN PROCEDURE BPROC Argument Name Type In/Out Default? ------------------------------ ----------------------- ------ -------- P1 CHAR IN P2 NUMBER IN

To create and describe the object type ADDRESS that contains the attributes STREET and CITY, enter

Keyboard icon
CREATE TYPE ADDRESS AS OBJECT ( STREET VARCHAR2(20), CITY VARCHAR2(20) ); / Screen icon
Type created. Keyboard icon
DESCRIBE address Screen icon
Name Null? Type ----------------------------------------- -------- ---------------------------- STREET VARCHAR2(20) CITY VARCHAR2(20)

To create and describe the object type EMPLOYEE that contains the attributes LAST_NAME, EMPADDR, JOB_ID and SALARY, enter

Keyboard icon
CREATE TYPE EMPLOYEE AS OBJECT (LAST_NAME VARCHAR2(30), EMPADDR ADDRESS, JOB_ID VARCHAR2(20), SALARY NUMBER(7,2) ); / Screen icon
Type created. Keyboard icon
DESCRIBE employee Screen icon
Name Null? Type ----------------------------------------- -------- ---------------------------- LAST_NAME VARCHAR2(30) EMPADDR ADDRESS JOB_ID VARCHAR2(20) SALARY NUMBER(7,2)

To create and describe the object type addr_type as a table of the object type ADDRESS, enter

Keyboard icon
CREATE TYPE addr_type IS TABLE OF ADDRESS; / Screen icon
Type created. Keyboard icon
DESCRIBE addr_type Screen icon
addr_type TABLE OF ADDRESS Name Null? Type ----------------------------------------- -------- ---------------------------- STREET VARCHAR2(20) CITY VARCHAR2(20)

To create and describe the object type addr_varray as a varray of the object type ADDRESS, enter

Keyboard icon
CREATE TYPE addr_varray AS VARRAY(10) OF ADDRESS; / Screen icon
Type created. Keyboard icon
DESCRIBE addr_varray Screen icon
addr_varray VARRAY(10) OF ADDRESS Name Null? Type ----------------------------------------- -------- ---------------------------- STREET VARCHAR2(20) CITY VARCHAR2(20)

To create and describe the table department that contains the columns DEPARTMENT_ID, PERSON and LOC, enter

Keyboard icon
CREATE TABLE department (DEPARTMENT_ID NUMBER, PERSON EMPLOYEE, LOC NUMBER ); / Screen icon
Table created. Keyboard icon
DESCRIBE department Screen icon
Name Null? Type ----------------------------------------- -------- ---------------------------- DEPARTMENT_ID NUMBER PERSON EMPLOYEE LOC NUMBER

To create and describe the object type rational that contains the attributes NUMERATOR and DENOMINATOR, and the METHOD rational_order, enter

Keyboard icon
CREATE OR REPLACE TYPE rational AS OBJECT (NUMERATOR NUMBER, DENOMINATOR NUMBER, MAP MEMBER FUNCTION rational_order - RETURN DOUBLE PRECISION, PRAGMA RESTRICT_REFERENCES (rational_order, RNDS, WNDS, RNPS, WNPS) ); / CREATE OR REPLACE TYPE BODY rational AS OBJECT MAP MEMBER FUNCTION rational_order - RETURN DOUBLE PRECISION IS BEGIN RETURN NUMERATOR/DENOMINATOR; END; END; / Keyboard icon
DESCRIBE rational Screen icon
Name Null? Type ------------------------------ -------- ------------ NUMERATOR NUMBER DENOMINATOR NUMBER METHOD ------ MAP MEMBER FUNCTION RATIONAL_ORDER RETURNS NUMBER

To create a table which contains a column of XMLType, and describe it, enter

Keyboard icon
CREATE TABLE PROPERTY (Price NUMBER, Description SYS.XMLTYPE); Screen icon
Table created Keyboard icon
DESCRIBE PROPERTY; Screen icon
Name Null? Type ----------------------------------------- -------- ---------------------------- PRICE NUMBER DESCRIPTION SYS.XMLTYPE

To format the DESCRIBE output use the SET command as follows:

Keyboard icon
SET LINESIZE 80 SET DESCRIBE DEPTH 2 SET DESCRIBE INDENT ON SET DESCRIBE LINE OFF

To display the settings for the object, use the SHOW command as follows:

Keyboard icon
SHOW DESCRIBE Screen icon
DESCRIBE DEPTH 2 LINENUM OFF INDENT ON Keyboard icon
DESCRIBE employee Screen icon
Name Null? Type ----------------------------------------- -------- ---------------------------- FIRST_NAME VARCHAR2(30) EMPADDR ADDRESS STREET VARCHAR2(20) CITY VARCHAR2(20) JOB_ID VARCHAR2(20) SALARY NUMBER(7,2)

For more information on using the CREATE TYPE command, see your Oracle9i SQL Reference.

For information about using the SET DESCRIBE and SHOW DESCRIBE commands, see the SET and SHOW commands later in this chapter.

DISCONNECT

DISC[ONNECT]

Commits pending changes to the database and logs the current username out of Oracle, but does not exit SQL*Plus.

Usage

Use DISCONNECT within a script to prevent user access to the database when you want to log the user out of Oracle but have the user remain in SQL*Plus. Use Logout in iSQL*Plus, and EXIT or QUIT in SQL*Plus command-line to log out of Oracle and return control to your host computer's operating system.

Examples

Your script might begin with a CONNECT command and end with a DISCONNECT, as shown below.

Keyboard icon
CONNECT HR/your_password SELECT LAST_NAME, DEPARTMENT_NAME FROM EMP_DETAILS_VIEW; DISCONNECT SET INSTANCE FIN2 CONNECT HR2/your_password

EDIT

EDIT is not available in iSQL*Plus.

ED[IT] [file_name[.ext]]

Invokes a host operating system text editor on the contents of the specified file or on the contents of the buffer.

Terms

Refer to the following for a description of the term or clause:

file_name[.ext]

Represents the file you wish to edit (typically a script).

Enter EDIT with no filename to edit the contents of the SQL buffer with the host operating system text editor.

Usage

If you omit the file extension, SQL*Plus assumes the default command-file extension (normally SQL). For information on changing the default extension, see the SUFFIX variable of the SET command in this chapter.

If you specify a filename, SQL*Plus searches for the file in the current working directory. If SQL*Plus cannot find the file in the current working directory, it creates a file with the specified name.

The user variable, _EDITOR, contains the name of the text editor invoked by EDIT. You can change the text editor by changing the value of _EDITOR. See COPY for information about changing the value of a user variable. If _EDITOR is undefined, EDIT attempts to invoke the default host operating system editor.

EDIT alone places the contents of the SQL buffer in a file by default named AFIEDT.BUF (in your current working directory) and invokes the text editor on the contents of the file. If the file AFIEDT.BUF already exists, it is overwritten with the contents of the buffer. You can change the default filename by using the SET EDITFILE command. For more information about setting a default filename for the EDIT command, see the EDITFILE variable of the SET command in this chapter.


Note:

The default file, AFIEDT.BUF, may have a different name on some operating systems.


If you do not specify a filename and the buffer is empty, EDIT returns an error message.

To leave the editing session and return to SQL*Plus, terminate the editing session in the way customary for the text editor. When you leave the editor, SQL*Plus loads the contents of the file into the buffer.

Examples

To edit the file REPORT with the extension SQL using your host operating system text editor, enter

Keyboard icon
EDIT REPORT

EXECUTE

EXEC[UTE] statement

Executes a single PL/SQL statement. The EXECUTE command is often useful when you want to execute a PL/SQL statement that references a stored procedure. For more information on PL/SQL, see your PL/SQL User's Guide and Reference.

Terms

Refer to the following for a description of the term or clause:

statement

Represents a PL/SQL statement.

Usage

If your EXECUTE command cannot fit on one line because of the PL/SQL statement, use the SQL*Plus continuation character (a hyphen).

The length of the command and the PL/SQL statement cannot exceed the length defined by SET LINESIZE.

Examples

If the variable :n has been defined with:

Keyboard icon
VARIABLE n NUMBER

The following EXECUTE command assigns a value to the bind variable n:

Keyboard icon
EXECUTE :n := 1 Screen icon
PL/SQL procedure successfully completed.

For information on how to create a bind variable, see the VARIABLE command in this chapter.

EXIT

{EXIT|QUIT} [SUCCESS|FAILURE|WARNING|n|variable|:BindVariable] [COMMIT|ROLLBACK]

Commits or rolls back all pending changes, logs out of Oracle, terminates SQL*Plus and returns control to the operating system.

In iSQL*Plus, commits or rolls back all pending changes, stops processing the current iSQL*Plus script and returns focus to the Input area. There is no way to access the return code in iSQL*Plus. In iSQL*Plus click the Logout button to log out of Oracle.

Terms

Refer to the following list for a description of each term or clause:

{EXIT|QUIT}

Can be used interchangeably (QUIT is a synonym for EXIT).

SUCCESS

Exits normally.

FAILURE

Exits with a return code indicating failure.

WARNING

Exits with a return code indicating warning.

COMMIT

Saves pending changes to the database before exiting.

n

Represents an integer you specify as the return code.

variable

Represents a user-defined or system variable (but not a bind variable), such as SQL.SQLCODE. EXIT variable exits with the value of variable as the return code.

:BindVariable

Represents a variable created in SQL*Plus with the VARIABLE command, and then referenced in PL/SQL, or other subprograms. :BindVariable exits the subprogram and returns you to SQL*Plus.

ROLLBACK

Executes a ROLLBACK statement and abandons pending changes to the database before exiting.

EXIT with no clauses commits and exits with a value of SUCCESS.

Usage

EXIT allows you to specify an operating system return code. This allows you to run SQL*Plus scripts in batch mode and to detect programmatically the occurrence of an unexpected event. The manner of detection is operating-system specific. See the Oracle installation and user's manual(s) provided for your operating system for details.

The key words SUCCESS, WARNING, and FAILURE represent operating-system dependent values. On some systems, WARNING and FAILURE may be indistinguishable.

The range of operating system return codes is also restricted on some operating systems. This limits the portability of EXIT n and EXIT variable between platforms. For example, on UNIX there is only one byte of storage for return codes; therefore, the range for return codes is limited to zero to 255.

If you make a syntax error in the EXIT options or use a non-numeric variable, SQL*Plus performs an EXIT FAILURE COMMIT.

For information on exiting conditionally, see the WHENEVER SQLERROR and WHENEVER OSERROR commands later in this chapter.

Examples

The following example commits all uncommitted transactions and returns the error code of the last executed SQL command or PL/SQL block:

Keyboard icon
EXIT SQL.SQLCODE

GET

GET is not available in iSQL*Plus. In iSQL*Plus use Load Script.

GET [FILE] file_name[.ext] [LIS[T]|NOL[IST]]

Loads a host operating system file into the SQL buffer.

Terms

Refer to the following list for a description of each term or clause:

FILE

Keyword to specify that the following argument is the name of the script you want to load. This optional keyword is usually omitted.

If you want to load a script with the name file, because it is a command keyword, you need to put the name file in single quotes.

file_name[.ext]

Represents the file you wish to load (typically a script).

LIS[T]

Lists the contents of the file after it is loaded. This is the default.

NOL[IST]

Suppresses the listing.

Usage

If you do not specify a file extension, SQL*Plus assumes the default command-file extension (normally SQL). For information on changing the default extension, see the SUFFIX variable of the SET command in this chapter.

If the filename you specify contains the word list or the word file, the name must be in double quotes. SQL*Plus searches for the file in the current working directory.

The operating system file should contain a single SQL statement or PL/SQL block. The statement should not be terminated with a semicolon. If a SQL*Plus command or more than one SQL statement or PL/SQL block is loaded into the SQL buffer from an operating system file, an error occurs when the RUN or slash (/) command is used to execute the buffer.

The GET command can be used to load files created with the SAVE command. See the SAVE command in this chapter for more information.

Examples

To load a file called YEARENDRPT with the extension SQL into the buffer, enter

Keyboard icon
GET YEARENDRPT

HELP

HELP [topic]

Accesses the SQL*Plus command-line help system. Enter HELP INDEX for a list of topics.

Terms

Refer to the following for a description of the term or clause:

topic

Represents a SQL*Plus help topic, for example, COLUMN.

Enter HELP without topic to get help on the help system.

Usage

You can only enter one topic after HELP. You can abbreviate the topic (for example, COL for COLUMN). However, if you enter only an abbreviated topic and the abbreviation is ambiguous, SQL*Plus displays help for all topics that match the abbreviation. For example, if you enter

HELP EX

SQL*Plus displays the syntax for the EXECUTE command followed by the syntax for the EXIT command.

If you get a response indicating that help is not available, consult your database administrator.

Examples

To see a list of SQL*Plus commands for which help is available, enter

Keyboard icon
HELP INDEX

Alternatively, to see a single column display of SQL*Plus commands for which help is available, enter

Keyboard icon
HELP TOPICS

HOST

HOST is not available in iSQL*Plus.

HO[ST] [command]

Executes a host operating system command without leaving SQL*Plus.

Terms

Refer to the following for a description of the term or clause:

command

Represents a host operating system command.

Enter HOST without command to display an operating system prompt. You can then enter multiple operating system commands. For information on returning to SQL*Plus, refer to the Oracle installation and user's manual(s) provided for your operating system.


Note:

Operating system commands entered from a SQL*Plus session using the HOST command do not effect the current SQL*Plus session. For example, setting an operating system environment variable does not effect the current SQL*Plus session, it only effects SQL*Plus sessions started subsequently.

You can suppress access to the HOST command. For more information about suppressing the HOST command see Chapter 10, "SQL*Plus Security".


Usage

With some operating systems, you can use a "$" (VMS), "!" (UNIX), or another character instead of HOST. See the Oracle installation and user's manual(s) provided for your operating system for details.

You may not have access to the HOST command, depending on your operating system. See the Oracle installation and user's manual(s) provided for your operating system or ask your DBA for more information.

SQL*Plus removes the SQLTERMINATOR (a semicolon by default) before the HOST command is issued. A workaround for this is to add another SQLTERMINATOR. See the SQLTERMINATOR variable of the SET command in this chapter for more information on the SQLTERMINATOR.

Examples

To execute a UNIX operating system command, ls *.sql, enter

Keyboard icon
HOST ls *.sql

To execute a Windows operating system command, dir *.sql, enter

Keyboard icon
HOST dir *.sql

INPUT

INPUT is not available in iSQL*Plus.

I[NPUT] [text]

Adds one or more new lines of text after the current line in the buffer.

Terms

Refer to the following for a description of the term or clause:

text

Represents the text you wish to add. To add a single line, enter the text of the line after the command INPUT, separating the text from the command with a space. To begin the line with one or more spaces, enter two or more spaces between INPUT and the first non-blank character of text.

To add several lines, enter INPUT with no text. INPUT prompts you for each line. To leave INPUT, enter a null (empty) line or a period.

Usage

If you enter a line number at the command prompt larger than the number of lines in the buffer, and follow the number with text, SQL*Plus adds the text in a new line at the end of the buffer. If you specify zero (0) for the line number and follow the zero with text, then SQL*Plus inserts the line at the beginning of the buffer (that line becomes line 1).

Examples

Assume the SQL buffer contains the following command:

Keyboard icon
SELECT LAST_NAME, DEPARTMENT_ID, SALARY, COMMISSION_PCT FROM EMP_DETAILS_VIEW

To add an ORDER BY clause to the query, enter

Keyboard icon
LIST 2 Screen icon
2* FROM EMP_DETAILS_VIEW Keyboard icon
INPUT ORDER BY LAST_NAME

LIST 2 ensures that line 2 is the current line. INPUT adds a new line containing the ORDER BY clause after the current line. The SQL buffer now contains the following lines:

Screen icon
1 SELECT LAST_NAME, DEPARTMENT_ID, SALARY, COMMISSION_PCT 2 FROM EMP_DETAILS_VIEW 3* ORDER BY LAST_NAME

To add a two-line WHERE clause, enter

Keyboard icon
LIST 2 Screen icon
2* FROM EMP_DETAILS_VIEW Keyboard icon
INPUT 3 WHERE JOB_ID = 'SA_MAN' 4 AND COMMISSION_PCT=.25 5

INPUT prompts you for new lines until you enter an empty line or a period. The SQL buffer now contains the following lines:

Screen icon
SELECT LAST_NAME, DEPARTMENT_ID, SALARY, COMMISSION_PCT FROM EMP_DETAILS_VIEW WHERE JOB_ID = 'SA_MAN' AND COMMISSION_PCT = .25 ORDER BY LAST_NAME

LIST

L[IST] [n|n m|n *|n LAST|*|* n|* LAST|LAST]

Lists one or more lines of the SQL buffer.

Terms

Refer to the following list for a description of each term or clause:

n

Lists line n.

n m

Lists lines n through m.

n *

Lists line n through the current line.

n LAST

Lists line n through the last line.

*

Lists the current line.

* n

Lists the current line through line n.

* LAST

Lists the current line through the last line.

LAST

Lists the last line.

Enter LIST with no clauses to list all lines. The last line or only line listed becomes the new current line (marked by an asterisk).

Examples

To list the contents of the buffer, enter

Keyboard icon
LIST

You will see a listing of all lines in the buffer, similar to the following example:

Screen icon
1 SELECT LAST_NAME, DEPARTMENT_ID, JOB_ID 2 FROM EMP_DETAILS_VIEW 3 WHERE JOB_ID = 'SH_CLERK' 4* ORDER BY DEPARTMENT_ID

The asterisk indicates that line 4 is the current line.

To list the second line only, enter

Keyboard icon
LIST 2

The second line is displayed:

Screen icon
2* FROM EMP_DETAILS_VIEW

To list the current line (now line 2) to the last line, enter

Keyboard icon
LIST * LAST

You will then see this:

Screen icon
2 FROM EMP_DETAILS_VIEW 3 WHERE JOB_ID = 'SH_CLERK' 4* ORDER BY DEPARTMENT_ID

PASSWORD

PASSWORD is not available in iSQL*Plus. In iSQL*Plus use the Password screen.

PASSW[ORD] [username]

Allows you to change a password without echoing it on an input device.

Terms

Refer to the following for a description of the clause or term:

username

Specifies the user. If omitted, username defaults to the current user.

Usage

To change the password of another user, you must have been granted the appropriate privilege. For more information about changing your password, see the CONNECT command in this chapter.

Examples

If you want to change your current password, enter

Keyboard iconScreen icon
PASSWORD Changing password for your_password Old password: your_password New password: new_password Retype new password: new_password Password changed

If you are logged on as a DBA, and want to change the password for user johnw (currently identified by johnwpass) to johnwnewpass

Keyboard iconScreen icon
PASSWORD johnw Changing password for johnw New password: johnwnewpass Retype new password: johnwnewpass Password changed

Passwords are not echoed to the screen, they are shown here for your convenience.

PAUSE

PAUSE is not available in iSQL*Plus.

PAU[SE] [text]

Displays the specified text then waits for the user to press RETURN.

Terms

Refer to the following for a description of the clause or term:

text

Represents the text you wish to display.

Enter PAUSE followed by no text to display two empty lines.

Usage

Because PAUSE always waits for the user's response, it is best to use a message that tells the user explicitly to press [Return].

PAUSE reads input from the terminal (if a terminal is available) even when you have designated the source of the command input as a file.

For information on pausing between pages of a report, see the PAUSE variable of the SET command later in this chapter.

Examples

To print "Adjust paper and press RETURN to continue." and to have SQL*Plus wait for the user to press [Return], you might include the following PAUSE command in a script:

Keyboard icon
SET PAUSE OFF PAUSE Adjust paper and press RETURN to continue. SELECT ...

PRINT

PRI[NT] [variable ...]

Displays the current values of bind variables. For more information on bind variables, see your PL/SQL User's Guide and Reference.

Terms

Refer to the following for a description of the clause or term:

variable ...

Represents names of bind variables whose values you wish to display.

Enter PRINT with no variables to print all bind variables.

Usage

Bind variables are created using the VARIABLE command. For more information and examples, see the VARIABLE command in this chapter.

You can control the formatting of the PRINT output just as you would query output. For more information, see the formatting techniques described in Chapter 7, "Formatting SQL*Plus Reports".

To automatically display bind variables referenced in a successful PL/SQL block or used in an EXECUTE command, use the AUTOPRINT clause of the SET command. For more information, see the SET command in this chapter.

Examples

The following example illustrates a PRINT command:

Keyboard icon
VARIABLE n NUMBER BEGIN :n := 1; END; / Screen icon
PL/SQL procedure successfully completed. Keyboard icon
PRINT n Screen icon
N ---------- 1

PROMPT

PRO[MPT] [text]

Sends the specified message or a blank line to the user's screen.

Terms

Refer to the following for a description of the term or clause:

text

Represents the text of the message you wish to display. If you omit text, PROMPT displays a blank line on the user's screen.

Usage

You can use this command in scripts to give information to the user.

Examples

The following example shows the use of PROMPT in conjunction with ACCEPT in a script called ASKFORDEPT. ASKFORDEPT contains the following SQL*Plus and SQL commands:

Keyboard icon
PROMPT PROMPT Please enter a valid department PROMPT For example: 10, 20, 30, 40 SELECT DEPARTMENT_NAME FROM EMP_DETAILS_VIEW WHERE DEPARTMENT_ID = &NEWDEPT

Assume you run the file using START or @:

Keyboard icon
@YEAREND.SQL VAL1 VAL2.SQL VAL1 VAL2x Screen icon
Please enter a valid department For example: 10, 20, 30, 40 Department ID?>

You can enter a department number at the prompt Department ID?>. By default, SQL*Plus lists the line containing &NEWDEPT before and after substitution, and then displays the department name corresponding to the number entered at the Department ID?> prompt. You can use SET VERIFY OFF to prevent this behavior.

RECOVER

RECOVER {general | managed | END BACKUP}

where the general clause has the following syntax:

[AUTOMATIC] [FROM location]
{ {full_database_recovery | partial_database_recovery |LOGFILE filename}
[ {TEST | ALLOW integer CORRUPTION } [TEST | ALLOW integer CORRUPTION ]...]
|CONTINUE [DEFAULT]|CANCEL}

where the full_database_recovery clause has the following syntax:

[STANDBY] DATABASE
[ {UNTIL {CANCEL | TIME date | CHANGE integer} | USING BACKUP CONTROLFILE}
[UNTIL {CANCEL | TIME date | CHANGE integer} | USING BACKUP CONTROLFILE]...]

where the partial_database_recovery clause has the following syntax:

{TABLESPACE tablespace [, tablespace]... | DATAFILE datafilename [, datafilename]...
| STANDBY
{TABLESPACE tablespace [, tablespace]... | DATAFILE datafilename [, datafilename]...}
UNTIL [CONSISTENT] [WITH] CONTROLFILE }

where the managed clause has the following syntax:

MANAGED STANDBY DATABASE
[ {NODELAY | [TIMEOUT] integer | CANCEL [IMMEDIATE] [NOWAIT]}
| [DISCONNECT [FROM SESSION] ] [FINISH [NOWAIT] ] ]

Performs media recovery on one or more tablespaces, one or more datafiles, or the entire database. For more information on the RECOVER command, see the Oracle9i Database Administrator's Guide, the ALTER DATABASE RECOVER command in the Oracle9i SQL Reference, the Oracle9i Backup and Recovery ConceptsOracle9i Backup and Recovery Concepts guide, and the Oracle9i User-Managed Backup and Recovery Guide.

Because of possible network timeouts, it is recommended that you use SQL*Plus command-line for long running DBA operations such as RECOVER.

You must set AUTORECOVERY ON to use the RECOVER command in iSQL*Plus. Attempting to RECOVER a database with AUTORECOVERY OFF raises the error:

SP2-0872 SET AUTORECOVERY ON must be used in iSQL*Plus

Terms

Refer to the following list for a description of each term and clause:

AUTOMATIC

Automatically generates the name of the next archived redo log file needed to continue the recovery operation. Oracle uses the LOG_ARCHIVE_DEST (or LOG_ARCHIVE_DEST_1) and LOG_ARCHIVE_FORMAT parameters (or their defaults) to generate the target redo log filename. If the file is found, the redo contained in that file is applied. If the file is not found, SQL*Plus prompts you for a filename, displaying a generated filename as a suggestion.

If you do not specify either AUTOMATIC or LOGFILE, SQL*Plus prompts you for a filename, suggesting the generated filename. You can then accept the generated filename or replace it with a fully qualified filename. If you know the archived filename differs from what Oracle would generate, you can save time by using the LOGFILE clause.

FROM location

Specifies the location from which the archived redo log file group is read. The value of location must be a fully specified file location following the conventions of your operating system. If you omit this parameter, SQL*Plus assumes the archived redo log file group is in the location specified by the initialization parameter LOG_ARCHIVE_DEST or LOG_ARCHIVE_DEST_1. Do not specify FROM if you have set a file with SET LOGSOURCE.

LOGFILE

Continues media recovery by applying the specified redo log file. In interactive recovery mode (AUTORECOVERY OFF), if a bad log name is entered, errors for the bad log name are displayed and you are prompted to enter a new log name.

TEST ALLOW integer CORRUPTION

In the event of logfile corruption, specifies the number of corrupt blocks that can be tolerated while allowing recovery to proceed. During normal recovery, integer cannot exceed 1.

CONTINUE

Continues multi-instance recovery after it has been interrupted to disable a thread.

CONTINUE DEFAULT

Continues recovery using the redo log file generated automatically by Oracle if no other logfile is specified. This is equivalent to specifying AUTOMATIC, except that Oracle does not prompt for a filename.

CANCEL

Terminates cancel-based recovery.

STANDBY DATABASE

Recovers the standby database using the control file and archived redo log files copied from the primary database. The standby database must be mounted but not open.

DATABASE

Recovers the entire database.

UNTIL CANCEL

Specifies an incomplete, cancel-based recovery. Recovery proceeds by prompting you with suggested filenames of archived redo log files, and recovery completes when you specify CANCEL instead of a filename.

UNTIL TIME

Specifies an incomplete, time-based recovery. Use single quotes, and the following format:

'YYYY-MM-DD:HH24:MI:SS'

UNTIL CHANGE

Specifies an incomplete, change-based recovery. integer is the number of the System Change Number (SCN) following the last change you wish to recover. For example, if you want to restore your database up to the transaction with an SCN of 9, you would specify UNTIL CHANGE 10.

USING BACKUP CONTROLFILE

Specifies that a backup of the control file be used instead of the current control file.

TABLESPACE

Recovers a particular tablespace. tablespace is the name of a tablespace in the current database. You may recover up to 16 tablespaces in one statement.

DATAFILE

Recovers a particular datafile. You can specify any number of datafiles.

STANDBY TABLESPACE

Reconstructs a lost or damaged tablespace in the standby database using archived redo log files copied from the primary database and a control file.

STANDBY DATAFILE

Reconstructs a lost or damaged datafile in the standby database using archived redo log files copied from the primary database and a control file.

UNTIL CONSISTENT WITH CONTROLFILE

Specifies that the recovery of an old standby datafile or tablespace uses the current standby database control file.

MANAGED STANDBY DATABASE

Specifies sustained standby recovery mode. This mode assumes that the standby database is an active component of an overall standby database architecture. A primary database actively archives its redo log files to the standby site. As these archived redo logs arrive at the standby site, they become available for use by a managed standby recovery operation. Sustained standby recovery is restricted to media recovery.

For more information on the parameters of this clause, see the Oracle9i User-Managed Backup and Recovery Guide.

NODELAY

Applies a delayed archivelog immediately to the standby database overriding any DELAY setting in the LOG_ARCHIVE_DEST_n parameter on the primary database. If you omit this clause, application of the archivelog is delayed according to the parameter setting. If DELAY was not specified in the parameter, the archivelog is applied immediately.

TIMEOUT

Specifies in minutes the wait period of the sustained recovery operation. The recovery process waits for integer minutes for a requested archived log redo to be available for writing to the standby database. If the redo log file does not become available within that time, the recovery process terminates with an error message. You can then issue the statement again to return to sustained standby recovery mode.

If you do not specify this clause, the database remains in sustained standby recovery mode until you reissue the statement with the RECOVER CANCEL clause or until instance shutdown or failure.

CANCEL (managed clause)

In managed recovery, CANCEL terminates the managed standby recovery operation after applying the current archived redo file. Session control returns when the recovery process terminates.

CANCEL IMMEDIATE

Terminates the managed recovery operation after applying the current archived redo file or after the next redo log file read, whichever comes first. Session control returns when the recovery process terminates.

CANCEL IMMEDIATE cannot be issued from the same session that issued the RECOVER MANAGED STANDBY DATABASE statement.

CANCEL NOWAIT

Terminates the managed recovery operation after the next redo log file read and returns session control immediately.

DISCONNECT FROM SESSION

Indicates that the managed redo process (MRP) should apply archived redo files as a detached background process. Doing so leaves the current session available.

FINISH

Recovers the current log standby logfiles of the standby database. It is useful in the event of the primary database failure. This clause overrides any delays specified for archivelogs, so that Oracle logs are applied immediately.

NOWAIT

Returns control immediately rather than after completion of the recovery process.

Usage

You must have the OSDBA role enabled. You cannot use the RECOVER command when connected via the multi-threaded server.

To perform media recovery on an entire database (all tablespaces), the database must be mounted and closed, and all tablespaces requiring recovery must be online.

To perform media recovery on a tablespace, the database must be mounted and open, and the tablespace must be offline.

To perform media recovery on a datafile, the database can remain open and mounted with the damaged datafiles offline (unless the file is part of the SYSTEM tablespace).

Before using the RECOVER command you must have restored copies of the damaged datafile(s) from a previous backup. Be sure you can access all archived and online redo log files dating back to when that backup was made.

When another log file is required during recovery, a prompt suggests the names of files that are needed. The name is derived from the values specified in the initialization parameters LOG_ARCHIVE_DEST and LOG_ARCHIVE_FORMAT. You should restore copies of the archived redo log files needed for recovery to the destination specified in LOG_ARCHIVE_DEST, if necessary. You can override the initialization parameters by setting the LOGSOURCE variable with the SET LOGSOURCE command.

During recovery you can accept the suggested log name by pressing return, cancel recovery by entering CANCEL instead of a log name, or enter AUTO at the prompt for automatic file selection without further prompting.

If you have enabled autorecovery (that is, SET AUTORECOVERY ON), recovery proceeds without prompting you with filenames. Status messages are displayed when each log file is applied. When normal media recovery is done, a completion status is returned.

Examples

To recover the entire database, enter

Keyboard icon
RECOVER DATABASE

To recover the database until a specified time, enter

Keyboard icon
RECOVER DATABASE UNTIL TIME 01-JAN-2001:04:32:00

To recover the two tablespaces ts_one and ts_two from the database, enter

Keyboard icon
RECOVER TABLESPACE ts_one, ts_two

To recover the datafile data1.db from the database, enter

Keyboard icon
RECOVER DATAFILE 'data1.db'

REMARK

REM[ARK]

Begins a comment in a script. SQL*Plus does not interpret the comment as a command.

Usage

The REMARK command must appear at the beginning of a line, and the comment ends at the end of the line. A line cannot contain both a comment and a command.

A "-" at the end of a REMARK line is treated as a line continuation character.

For details on entering comments in scripts using the SQL comment delimiters, /* ... */, or the ANSI/ISO comment delimiter, - - ..., refer to "Placing Comments in Scripts".

Examples

The following script contains some typical comments:

Keyboard icon
REM COMPUTE uses BREAK ON REPORT to break on end of table BREAK ON REPORT COMPUTE SUM OF "DEPARTMENT 10" "DEPARTMENT 20" - "DEPARTMENT 30" "TOTAL BY JOB_ID" ON REPORT REM Each column displays the sums of salaries by job for REM one of the departments 10, 20, 30. SELECT JOB_ID, SUM(DECODE( DEPARTMENT_ID, 10, SALARY, 0)) "DEPARTMENT 10", SUM(DECODE( DEPARTMENT_ID, 20, SALARY, 0)) "DEPARTMENT 20", SUM(DECODE( DEPARTMENT_ID, 30, SALARY, 0)) "DEPARTMENT 30", SUM(SALARY) "TOTAL BY JOB_ID" FROM EMP_DETAILS_VIEW GROUP BY JOB_ID;

REPFOOTER

REPF[OOTER] [PAGE] [printspec [text|variable] ...] | [ON|OFF]

where printspec represents one or more of the following clauses used to place and format the text:

COL n
S[KIP] [n]
TAB n
LE[FT]
CE[NTER]
R[IGHT]
BOLD
FORMAT text

Places and formats a specified report footer at the bottom of each report, or lists the current REPFOOTER definition.

Terms

Refer to the REPHEADER command for additional information on terms and clauses in the REPFOOTER command syntax.

Enter REPFOOTER with no clauses to list the current REPFOOTER definition.

Usage

If you do not enter a printspec clause before the text or variables, REPFOOTER left justifies the text or variables.

You can use any number of constants and variables in a printspec. SQL*Plus displays the constants and variables in the order you specify them, positioning and formatting each constant or variable as specified by the printspec clauses that precede it.


Note:

If SET EMBEDDED is ON, the report footer is suppressed.


Examples

To define "END EMPLOYEE LISTING REPORT" as a report footer on a separate page and to center it, enter:

Keyboard icon
REPFOOTER PAGE CENTER 'END EMPLOYEE LISTING REPORT' TTITLE RIGHT 'Page: ' FORMAT 999 SQL.PNO SELECT LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE SALARY > 12000; Screen icon
LAST_NAME SALARY ------------------------- ---------- King 24000 Kochhar 17000 De Haan 17000 Russell 14000 Partners 13500 Hartstein 13000 ---------- sum 98500 Page: 2 END EMPLOYEE LISTING REPORT 6 rows selected.

To suppress the report footer without changing its definition, enter

Keyboard icon
REPFOOTER OFF

REPHEADER

REPH[EADER] [PAGE] [printspec [text|variable] ...] | [ON|OFF]

where printspec represents one or more of the following clauses used to place and format the text:

COL n
S[KIP] [n]
TAB n
LE[FT]
CE[NTER]
R[IGHT]
BOLD
FORMAT text

Places and formats a specified report header at the top of each report, or lists the current REPHEADER definition.

Terms

Refer to the following list for a description of each term or clause. These terms and clauses also apply to the REPFOOTER command.

PAGE

Begins a new page after printing the specified report header or before printing the specified report footer.

text

The report header or footer text. Enter text in single quotes if you want to place more than one word on a single line. The default is NULL.

variable

A user variable or any of the following system-maintained values. SQL.LNO is the current line number, SQL.PNO is the current page number, SQL.CODE is the current error code, SQL.RELEASE is the current Oracle release number, and SQL.USER is the current username.

To print one of these values, reference the appropriate variable in the report header or footer. You can format variable with the FORMAT clause.

OFF

Turns the report header or footer off (suppresses its display) without affecting its definition.

COL n

Indents to column n of the current line (backward if column n has been passed). Column in this context means print position, not table column.

S[KIP] [n]

Skips to the start of a new line n times; if you omit n, one time; if you enter zero for n, backward to the start of the current line.

TAB n

Skips forward n columns (backward if you enter a negative value for n). Column in this context means print position, not table column.

LE[FT] CE[NTER] R[IGHT]

Left-align, center, and right-align data on the current line respectively. SQL*Plus aligns following data items as a group, up to the end of the printspec or the next LEFT, CENTER, RIGHT, or COL command. CENTER and RIGHT use the SET LINESIZE value to calculate the position of the data item that follows.

BOLD

Prints data in bold print. SQL*Plus represents bold print on your terminal by repeating the data on three consecutive lines. On some operating systems, SQL*Plus may instruct your printer to print bold text on three consecutive lines, instead of bold.

FORMAT text

Specifies a format model that determines the format of data items up to the next FORMAT clause or the end of the command. The format model must be a text constant such as A10 or $999. See COLUMN FORMAT for more information on formatting and valid format models.

If the datatype of the format model does not match the datatype of a given data item, the FORMAT clause has no effect on that item.

If no appropriate FORMAT model precedes a given data item, SQL*Plus prints NUMBER values according to the format specified by SET NUMFORMAT or, if you have not used SET NUMFORMAT, the default format. SQL*Plus prints DATE values using the default format.

Refer to the FORMAT clause of the COLUMN command in this chapter for more information on default formats.

Enter REPHEADER with no clauses to list the current REPHEADER definition.

Usage

If you do not enter a printspec clause before the text or variables, REPHEADER left justifies the text or variables.

You can use any number of constants and variables in a printspec. SQL*Plus displays the constants and variables in the order you specify, positioning and formatting each constant or variable as specified by the printspec clauses that precede it.

Examples

To define "EMPLOYEE LISTING REPORT" as a report header on a separate page, and to center it, enter:

Keyboard icon
REPHEADER PAGE CENTER 'EMPLOYEE LISTING REPORT' TTITLE RIGHT 'Page: ' FORMAT 999 SQL.PNO SELECT LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE SALARY > 12000; Screen icon
Page: 1 EMPLOYEE LISTING REPORT Page: 2 LAST_NAME SALARY ------------------------- ---------- King 24000 Kochhar 17000 De Haan 17000 Russell 14000 Partners 13500 Hartstein 13000 ---------- sum 98500 6 rows selected.

To suppress the report header without changing its definition, enter:

Keyboard icon
REPHEADER OFF

RUN

R[UN]

Lists and executes the SQL command or PL/SQL block currently stored in the SQL buffer.

Usage

RUN causes the last line of the SQL buffer to become the current line.

The slash command (/) functions similarly to RUN, but does not list the command in the SQL buffer on your screen. The SQL buffer always contains the last SQL statement or PL/SQL block entered.

Examples

Assume the SQL buffer contains the following script:

Keyboard icon
SELECT DEPARTMENT_ID FROM EMP_DETAILS_VIEW WHERE SALARY>12000

To RUN the script, enter

Keyboard icon
RUN Screen icon
1 SELECT DEPARTMENT_ID 2 FROM EMP_DETAILS_VIEW 3 WHERE SALARY>12000 DEPARTMENT_ID ------------- 90 90 90 80 80 20 6 rows selected.

SAVE

SAVE is not available in iSQL*Plus. In iSQL*Plus use Save Script.

SAV[E] [FILE] file_name[.ext] [CRE[ATE]|REP[LACE]|APP[END]]

Saves the contents of the SQL buffer in a host operating system script.

Terms

Refer to the following list for a description of each term or clause:

FILE

Keyword to specify that the following argument is the name you want to give to the saved script. This optional keyword is usually omitted.

If you want to save the script with the name file, because it is a command keyword, you need to put the name file in single quotes.

file_name[.ext]

Specifies the script in which you wish to save the buffer's contents.

CREATE

Creates a new file with the name specified. This is the default behavior.

REP[LACE]

Replaces the contents of an existing file. If the file does not exist, REPLACE creates the file.

APP[END]

Adds the contents of the buffer to the end of the file you specify.

Usage

If you do not specify an extension, SQL*Plus assumes the default command-file extension (normally SQL). For information on changing this default extension, see the SUFFIX variable of the SET command in this chapter.

If you wish to SAVE a file under a name identical to a SAVE command clause (CREATE, REPLACE, or APPEND), you must specify a file extension.

When you SAVE the contents of the SQL buffer, SAVE adds a line containing a slash (/) to the end of the file.

Examples

To save the contents of the buffer in a file named DEPTSALRPT with the extension SQL, enter

Keyboard icon
SAVE DEPTSALRPT

To save the contents of the buffer in a file named DEPTSALRPT with the extension OLD, enter

Keyboard icon
SAVE DEPTSALRPT.OLD

SET

Sets a system variable to alter the SQL*Plus environment settings for your current session, for example:

You can also use the System Variables screen in iSQL*Plus to set system variables.

SET system_variable value

where system_variable and value are shown in the SET commands following.

Usage

SQL*Plus maintains system variables (also called SET command variables) to enable you to setup a particular environment for a SQL*Plus session. You can change these system variables with the SET command and list them with the SHOW command.

SET ROLE and SET TRANSACTION are SQL commands (see the Oracle9i SQL Reference for more information). When not followed by the keywords TRANSACTION or ROLE, SET is assumed to be a SQL*Plus command.

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

Sets automatic registering of scripts through the DBMS_APPLICATION_INFO package. This enables the performance and resource usage of each script to be monitored by your DBA. The registered name appears in the MODULE column of the V$SESSION and V$SQLAREA virtual tables. You can also read the registered name using the DBMS_APPLICATION_INFO.READ_MODULE procedure.

ON registers scripts invoked by the @, @@ or START commands. OFF disables registering of scripts. Instead, the current value of text is registered. Text specifies the text to register when no script is being run or when APPINFO is OFF, which is the default. The default for text is "SQL*Plus". If you enter multiple words for text, you must enclose them in quotes. The maximum length for text is limited by the DBMS_APPLICATION_INFO package.

The registered name has the format nn@xfilename where: nn is the depth level of script; x is '<' when the script name is truncated, otherwise, it is blank; and filename is the script name, possibly truncated to the length allowed by the DBMS_APPLICATION_INFO package interface.


Note:

To use this feature, you must have access to the DBMS_APPLICATION_INFO package. Run DBMSUTIL.SQL (this name may vary depending on your operating system) as SYS to create the DBMS_APPLICATION_INFO package. DBMSUTIL.SQL is part of the Oracle9i database server product.


For more information on the DBMS_APPLICATION_INFO package, see the Oracle9i Database Performance Tuning Guide and Reference manual.

Example

To display the setting of APPINFO, as it is SET OFF by default, enter

Keyboard icon
SET APPINFO ON SHOW APPINFO Screen icon
APPINFO is ON and set to "SQL*Plus"

To change the default text, enter

Keyboard icon
SET APPINFO 'This is SQL*Plus'

To make sure that registration has taken place, enter

Keyboard icon
VARIABLE MOD VARCHAR2(50) VARIABLE ACT VARCHAR2(40) EXECUTE DBMS_APPLICATION_INFO.READ_MODULE(:MOD, :ACT); Screen icon
PL/SQL procedure successfully completed. Keyboard icon
PRINT MOD Screen icon
MOD --------------------------------------------------- This is SQL*Plus

To change APPINFO back to its default setting, enter

Keyboard icon
SET APPI OFF

SET ARRAY[SIZE] {15|n}

Sets the number of rows--called a batch--that SQL*Plus will fetch from the database at one time. Valid values are 1 to 5000. A large value increases the efficiency of queries and subqueries that fetch many rows, but requires more memory. Values over approximately 100 provide little added performance. ARRAYSIZE has no effect on the results of SQL*Plus operations other than increasing efficiency.

SET AUTO[COMMIT]{ON|OFF|IMM[EDIATE]|n}

Controls when Oracle commits pending changes to the database. ON commits pending changes to the database after Oracle executes each successful INSERT, UPDATE, or DELETE command or PL/SQL block. OFF suppresses automatic committing so that you must commit changes manually (for example, with the SQL command COMMIT). IMMEDIATE functions in the same manner as the ON option. n commits pending changes to the database after Oracle executes n successful SQL INSERT, UPDATE, or DELETE commands or PL/SQL blocks. n cannot be less than zero or greater than 2,000,000,000. The statement counter is reset to zero after successful completion of n INSERT, UPDATE or DELETE commands or PL/SQL blocks, a commit, a rollback, or a SET AUTOCOMMIT command.


Note:

For this feature, a PL/SQL block is considered one transaction, regardless of the actual number of SQL commands contained within it.


SET AUTOP[RINT] {ON|OFF}

Sets the automatic printing of bind variables. ON or OFF controls whether SQL*Plus automatically displays bind variables (referenced in a successful PL/SQL block or used in an EXECUTE command). For more information about displaying bind variables, see the PRINT command in this chapter.

SET AUTORECOVERY [ON|OFF]

ON sets the RECOVER command to automatically apply the default filenames of archived redo log files needed during recovery. No interaction is needed when AUTORECOVERY is set to ON, provided the necessary files are in the expected locations with the expected names. The filenames used when AUTORECOVERY is ON are derived from the values of the initialization parameters LOG_ARCHIVE_DEST and LOG_ARCHIVE_FORMAT.

You must set AUTORECOVERY ON to use the RECOVER command in iSQL*Plus. Attempting to RECOVER a database with AUTORECOVERY OFF raises the error:

SP2-0872 SET AUTORECOVERY ON must be used in iSQL*Plus

OFF, the default option, requires that you enter the filenames manually or accept the suggested default filename given. See the RECOVER command in this chapter for more information about database recovery.

Example

To set the recovery mode to AUTOMATIC, enter

Keyboard icon
SET AUTORECOVERY ON RECOVER DATABASE

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

Displays a report on the execution of successful SQL DML statements (SELECT, INSERT, UPDATE or DELETE). The report can include execution statistics and the query execution path.

OFF does not display a trace report. ON displays a trace report. TRACEONLY displays a trace report, but does not print query data, if any. EXPLAIN shows the query execution path by performing an EXPLAIN PLAN. STATISTICS displays SQL statement statistics. Information about EXPLAIN PLAN is documented in the Oracle9i SQL Reference manual.

Using ON or TRACEONLY with no explicit options defaults to EXPLAIN STATISTICS.

The TRACEONLY option may be useful to suppress the query data of large queries. If STATISTICS is specified, SQL*Plus still fetches the query data from the server, however, the data is not displayed.

The AUTOTRACE report is printed after the statement has successfully completed.

Information about Execution Plans and the statistics is documented in the Oracle9i Database Performance Tuning Guide and Reference manual.

When SQL*Plus produces a STATISTICS report, a second connection to the database is automatically created. This connection is closed when the STATISTICS option is set to OFF, or you log out of SQL*Plus.

The formatting of your AUTOTRACE report may vary depending on the version of the server to which you are connected and the configuration of the server.

AUTOTRACE is not available when FIPS flagging is enabled.

See "Tracing Statements" for more information on AUTOTRACE.

SET BLO[CKTERMINATOR] {.|c|ON|OFF}

Sets the character used to end PL/SQL blocks to c. It cannot be an alphanumeric character or a whitespace. To execute the block, you must issue a RUN or / (slash) command.

OFF means that SQL*Plus recognizes no PL/SQL block terminator. ON changes the value of c back to the default period (.), not the most recently used character.

SET CMDS[EP] {;|c|ON|OFF}

Sets the non-alphanumeric character used to separate multiple SQL*Plus commands entered on one line to c. ON or OFF controls whether you can enter multiple commands on a line. ON automatically sets the command separator character to a semicolon (;).

Example

To specify a title with TTITLE and format a column with COLUMN, both on the same line, enter

Keyboard icon
SET CMDSEP + TTITLE LEFT 'SALARIES' + COLUMN SALARY FORMAT $99,999 SELECT LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE JOB_ID = 'SH_CLERK'; Screen icon
SALARIES LAST_NAME SALARY ------------------------- -------- Taylor $3,200 Fleaur $3,100 Sullivan $2,500 Geoni $2,800 Sarchand $4,200 Bull $4,100 Dellinger $3,400 Cabrio $3,000 Chung $3,800 Dilly $3,600 Gates $2,900 Perkins $2,500 Bell $4,000 Everett $3,900 McCain $3,200 Jones $2,800 SALARIES LAST_NAME SALARY ------------------------- -------- Walsh $3,100 Feeney $3,000 OConnell $2,600 Grant $2,600 20 rows selected.

SET COLSEP {_|text}

In iSQL*Plus, SET COLSEP determines the column separator character to be printed between column output that is rendered inside tags. HTML table output is the default. To generate preformatted output you must set PREFORMAT ON with the SET MARKUP HTML PREFORMAT ON command.

Sets the text to be printed between selected columns. If the COLSEP variable contains blanks or punctuation characters, you must enclose it with single quotes. The default value for text is a single space.

In multi-line rows, the column separator does not print between columns that begin on different lines. The column separator does not appear on blank lines produced by BREAK ... SKIP n and does not overwrite the record separator. See SET RECSEP in this chapter for more information.

Example

To set the column separator to "|" enter

Keyboard icon
SET COLSEP '|' SELECT LAST_NAME, JOB_ID, DEPARTMENT_ID FROM EMP_DETAILS_VIEW WHERE DEPARTMENT_ID = 20; Screen icon
LAST_NAME |JOB_ID |DEPARTMENT_ID -------------------------|----------|------------- Hartstein |MK_MAN | 20 Fay |MK_REP | 20

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

Specifies the version of Oracle SQL syntax to use. Set COMPATIBILITY to V7 for Oracle7, or to V8 for Oracle8 or later. COMPATIBILITY always defaults to NATIVE. COMPATIBILITY should be correctly set for the version of Oracle SQL syntax you want to use on the database to which you are connected, otherwise, you may be unable to run any SQL commands.

Example

To run a script, SALARY.SQL, created with Oracle7 SQL syntax, enter

Keyboard icon
SET COMPATIBILITY V7 START SALARY

After running the file, reset compatibility to NATIVE to run scripts created for Oracle9i:

Keyboard icon
SET COMPATIBILITY NATIVE

Alternatively, you can add the command SET COMPATIBILITY V7 to the beginning of the script, and reset COMPATIBILITY to NATIVE at the end of the file.

SET CON[CAT] {.|c|ON|OFF}

Sets the character used to terminate a substitution variable reference when SQL*Plus would otherwise interpret the next character as a part of the variable name. SQL*Plus resets the value of CONCAT to a period when you switch CONCAT on.

SET COPYC[OMMIT] {0|n}

Controls the number of batches after which the COPY command commits changes to the database. COPY commits rows to the destination database each time it copies n row batches. Valid values are zero to 5000. You can set the size of a batch with the ARRAYSIZE variable. If you set COPYCOMMIT to zero, COPY performs a commit only at the end of a copy operation.

SET COPYTYPECHECK {ON|OFF}

Sets the suppression of the comparison of datatypes while inserting or appending to tables with the COPY command. This is to facilitate copying to DB2, which requires that a CHAR be copied to a DB2 DATE.

SET DEF[INE] {&|c|ON|OFF}

Sets the character used to prefix substitution variables to c. ON or OFF controls whether SQL*Plus will scan commands for substitution variables and replace them with their values. ON changes the value of c back to the default '&', not the most recently used character. The setting of DEFINE to OFF overrides the setting of the SCAN variable. For more information on the SCAN variable, see the SET SCAN command.

SET DESCRIBE [DEPTH {1|n|ALL}][LINENUM {ON|OFF}][INDENT {ON|OFF}]

Sets the depth of the level to which you can recursively describe an object. The valid range of the DEPTH clause is from 1 to 50. If you SET DESCRIBE DEPTH ALL, then the depth will be set to 50, which is the maximum level allowed. You can also display the line number and indentation of the attribute or column name when an object contains multiple object types. Use the SET LINESIZE command to control the width of the data displayed.

For more information about describing objects, see DESCRIBE earlier in this chapter.

Example

To describe the view EMP_DETAILS_VIEW to a depth of two levels, and indent the output while also displaying line numbers, first describe the view as follows:

Keyboard icon
DESCRIBE EMP_DETAILS_VIEW Screen icon
Name Null? Type ----------------------------------------- -------- ---------------------------- EMPLOYEE_ID NOT NULL NUMBER(6) JOB_ID NOT NULL VARCHAR2(10) MANAGER_ID NUMBER(6) DEPARTMENT_ID NUMBER(4) LOCATION_ID NUMBER(4) COUNTRY_ID CHAR(2) FIRST_NAME VARCHAR2(20) LAST_NAME NOT NULL VARCHAR2(25) SALARY NUMBER(8,2) COMMISSION_PCT NUMBER(2,2) DEPARTMENT_NAME NOT NULL VARCHAR2(30) JOB_TITLE NOT NULL VARCHAR2(35) CITY NOT NULL VARCHAR2(30) STATE_PROVINCE VARCHAR2(25) COUNTRY_NAME VARCHAR2(40) REGION_NAME VARCHAR2(25)

To format EMP_DETAILS_VIEW so that the output displays with indentation and line numbers, use the SET DESCRIBE command as follows:

Keyboard icon
SET DESCRIBE DEPTH 2 LINENUM ON INDENT ON

To display the above settings, enter

Keyboard icon
DESCRIBE EMP_DETAILS_VIEW Screen icon
Name Null? Type ------------------- -------- -------------------- 1 EMPLOYEE_ID NOT NULL NUMBER(6) 2 JOB_ID NOT NULL VARCHAR2(10) 3 MANAGER_ID NUMBER(6) 4 DEPARTMENT_ID NUMBER(4) 5 LOCATION_ID NUMBER(4) 6 COUNTRY_ID CHAR(2) 7 FIRST_NAME VARCHAR2(20) 8 LAST_NAME NOT NULL VARCHAR2(25) 9 SALARY NUMBER(8,2) 10 COMMISSION_PCT NUMBER(2,2) 11 DEPARTMENT_NAME NOT NULL VARCHAR2(30) 12 JOB_TITLE NOT NULL VARCHAR2(35) 13 CITY NOT NULL VARCHAR2(30) 14 STATE_PROVINCE VARCHAR2(25) 15 COUNTRY_NAME VARCHAR2(40) 16 REGION_NAME VARCHAR2(25)

SET ECHO {ON|OFF}

Controls whether the START command lists each command in a script as the command is executed. ON lists the commands; OFF suppresses the listing.

SET EDITF[ILE] file_name[.ext]

SET EDITFILE is not supported in iSQL*Plus

Sets the default filename for the EDIT command. For more information about the EDIT command, see EDIT in this chapter.

You can include a path and/or file extension. For information on changing the default extension, see the SUFFIX variable of the SET command. The default filename and maximum filename length are operating system specific.

SET EMB[EDDED] {ON|OFF}

Controls where on a page each report begins. OFF forces each report to start at the top of a new page. ON allows a report to begin anywhere on a page. Set EMBEDDED to ON when you want a report to begin printing immediately following the end of the previously run report.

SET ESC[APE] {\|c|ON|OFF}

Defines the character used as the escape character. OFF undefines the escape character. ON enables the escape character. ON changes the value of c back to the default "\".

You can use the escape character before the substitution character (set through SET DEFINE) to indicate that SQL*Plus should treat the substitution character as an ordinary character rather than as a request for variable substitution.

Example

If you define the escape character as an exclamation point (!), then

Keyboard icon
SET ESCAPE ! ACCEPT v1 PROMPT 'Enter !&1:'

displays this prompt:

Screen icon
Enter &1:

To set the escape character back to the default value of \ (backslash), enter

Keyboard icon
SET ESCAPE ON

SET FEED[BACK] {6|n|ON|OFF}

Displays the number of records returned by a script when a script selects at least n records. ON or OFF turns this display on or off. Turning feedback ON sets n to 1. Setting feedback to zero is equivalent to turning it OFF.

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

Checks to make sure that SQL statements conform to the ANSI/ISO SQL92 standard. If any non-standard constructs are found, the Oracle Server flags them as errors and displays the violating syntax. This is the equivalent of the SQL language ALTER SESSION SET FLAGGER command.

You may execute SET FLAGGER even if you are not connected to a database. FIPS flagging will remain in effect across SQL*Plus sessions until a SET FLAGGER OFF (or ALTER SESSION SET FLAGGER = OFF) command is successful or you exit SQL*Plus.

When FIPS flagging is enabled, SQL*Plus displays a warning for the CONNECT, DISCONNECT, and ALTER SESSION SET FLAGGER commands, even if they are successful.

SET FLU[SH] {ON|OFF}

SET FLUSH is not supported in iSQL*Plus

Controls when output is sent to the user's display device. OFF allows the host operating system to buffer output. ON disables buffering.

Use OFF only when you run a script non-interactively (that is, when you do not need to see output and/or prompts until the script finishes running). The use of FLUSH OFF may improve performance by reducing the amount of program I/O.

SET HEA[DING] {ON|OFF}

Controls printing of column headings in reports. ON prints column headings in reports; OFF suppresses column headings.

The SET HEADING OFF command will not affect the column width displayed, and only suppresses the printing of the column header itself.

Example

To suppress the display of column headings in a report, enter

Keyboard icon
SET HEADING OFF

If you then run a SQL SELECT command

Keyboard icon
SELECT LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE JOB_ID = 'AC_MGR';

the following output results:

Screen icon
Higgins 12000

To turn the display of column headings back on, enter

Keyboard icon
SET HEADING ON

SET HEADS[EP] {||c|ON|OFF}

Defines the character used as the heading separator character. The heading separator character cannot be alphanumeric or white space. You can use the heading separator character in the COLUMN command and in the old forms of BTITLE and TTITLE to divide a column heading or title onto more than one line. ON or OFF turns heading separation on or off. When heading separation is OFF, SQL*Plus prints a heading separator character like any other character. ON changes the value of c back to the default "|".

SET INSTANCE [instance_path|LOCAL]

Changes the default instance for your session to the specified instance path. Using the SET INSTANCE command does not connect to a database. The default instance is used for commands when no instance is specified. Any commands preceding the first use of SET INSTANCE communicate with the default instance.

To reset the instance to the default value for your operating system, you can either enter SET INSTANCE with no instance_path or SET INSTANCE LOCAL. See your operating system-specific Oracle documentation for a description of how to set the initial default instance.

Note, you can only change the instance when you are not currently connected to any instance. That is, you must first make sure that you have disconnected from the current instance, then set or change the instance, and reconnect to an instance in order for the new setting to be enabled.

This command may only be issued when Oracle Net is running. You can use any valid Oracle Net connect identifier as the specified instance path. See your operating system-specific Oracle documentation for a complete description of how your operating system specifies Oracle Net connect identifiers. The maximum length of the instance path is 64 characters.

Example

To set the default instance to "PROD1" enter

Keyboard icon
DISCONNECT SET INSTANCE PROD1

To set the instance back to the default of local, enter

Keyboard icon
SET INSTANCE local

You must disconnect from any connected instances to change the instance.

SET LIN[ESIZE] {80|n}

Sets the total number of characters that SQL*Plus displays on one line before beginning a new line. It also controls the position of centered and right-aligned text in TTITLE, BTITLE, REPHEADER and REPFOOTER. Changing the linesize setting can affect text wrapping in output from the DESCRIBE command. DESCRIBE output columns are typically allocated a proportion of the linesize. Decreasing or increasing the linesize may give unexpected text wrapping in your display. You can define LINESIZE as a value from 1 to a maximum that is system dependent. Refer to the Oracle installation and user's manual(s) provided for your operating system.

SET LOBOF[FSET] {n|1}

Sets the starting position from which CLOB and NCLOB data is retrieved and displayed.

Example

To set the starting position from which a CLOB column's data is retrieved to the 22nd position, enter

Keyboard icon
SET LOBOFFSET 22

The CLOB data will wrap on your screen; SQL*Plus will not truncate until the 23rd character.

SET LOGSOURCE [pathname]

Specifies the location from which archive logs are retrieved during recovery. The default value is set by the LOG_ARCHIVE_DEST initialization parameter in the Oracle initialization file, init.ora. Using the SET LOGSOURCE command without a pathname restores the default location.

Example

To set the default location of log files for recovery to the directory "/usr/oracle90/dbs/arch" enter

Keyboard icon
SET LOGSOURCE "/usr/oracle90/dbs/arch" RECOVER DATABASE

SET LONG {80|n}

Sets maximum width (in bytes) for displaying CLOB, LONG, NCLOB and XMLType values; and for copying LONG values. The maximum value of n is 2 gigabytes.

Example

To set the maximum number of bytes to fetch for displaying and copying LONG values, to 500, enter

Keyboard icon
SET LONG 500

The LONG data will wrap on your screen; SQL*Plus will not truncate until the 501st byte. The default for LONG is 80 bytes.

SET LONGC[HUNKSIZE] {80|n}

Sets the size (in bytes) of the increments SQL*Plus uses to retrieve a CLOB, LONG, NCLOB or XMLType value.

Example

To set the size of the increments in which SQL*Plus retrieves LONG values to 100 bytes, enter

Keyboard icon
SET LONGCHUNKSIZE 100

The LONG data will be retrieved in increments of 100 bytes until the entire value is retrieved or the value of SET LONG is reached, whichever is the smaller.

SET MARK[UP] HTML [ON|OFF] [HEAD text] [BODY text] [TABLE text] [ENTMAP {ON|OFF}][SPOOL {ON|OFF}] [PRE[FORMAT] {ON|OFF}]

Outputs HTML marked up text, which is the output used by iSQL*Plus. Beware of using options which generate invalid HTML output in iSQL*Plus as it may corrupt the browser screen. The HEAD and BODY options may be useful for dynamic reports and for reports saved to local files.

SET MARKUP only specifies that SQL*Plus output will be HTML encoded. You must use SET MARKUP HTML ON SPOOL ON and the SQL*Plus SPOOL command to create and name a spool file, and to begin writing HMTL output to it. SET MARKUP has the same options and behavior as SQLPLUS -MARKUP.

For detailed information see "MARKUP Options". For examples of usage, see SET MARKUP, and .

Use the SHOW MARKUP command to view the status of MARKUP options.

Example

The following is a script which uses the SET MARKUP HTML command to enable HTML marked up text to be spooled to a specified file:


Note:

The SET MARKUP example command is laid out for readability using line continuation characters "-" and spacing. Command options are concatenated in normal entry.


Use your favorite text editor to enter the commands necessary to set up the HTML options and the query you want for your report.

Keyboard icon
SET MARKUP HTML ON SPOOL ON HEAD "<TITLE>SQL*Plus Report</title> - STYLE TYPE='TEXT/CSS'><!--BODY {background: ffffc6} --></STYLE>" SET ECHO OFF SPOOL employee.htm"> SELECT FIRST_NAME, LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE SALARY>12000; SPOOL OFF SET MARKUP HTML OFF SET ECHO ON

As this script contains SQL*Plus commands, do not attempt to run it with / (slash) from the buffer because it will fail. Save the script in your text editor and use START to execute it:

Keyboard icon
START employee.sql

As well as writing the html spool file, employee.htm">/EM>, the output is also displayed on screen because SET TERMOUT defaults to ON. You can view the spool file, employee.htm"> in your web browser. It should appear something like the following:

Text description of markup.gif follows.

Text description of the illustration markup.gif

SET NEWP[AGE] {1|n|NONE}

SET NEWPAGE is not supported in iSQL*Plus

Sets the number of blank lines to be printed from the top of each page to the top title. A value of zero places a formfeed at the beginning of each page (including the first page) and clears the screen on most terminals. If you set NEWPAGE to NONE, SQL*Plus does not print a blank line or formfeed between the report pages.

SET NULL text

Sets the text that represents a null value in the result of a SQL SELECT command. Use the NULL clause of the COLUMN command to override the setting of the NULL variable for a given column.

SET NUMF[ORMAT] format

Sets the default format for displaying numbers. Enter a number format for format. For number format descriptions, see the FORMAT clause of the COLUMN command in this chapter.

SET NUM[WIDTH] {10|n}

Sets the default width for displaying numbers. For number format descriptions, see the FORMAT clause of the COLUMN command in this chapter.

SET PAGES[IZE] {24|n}

Sets the number of lines in each page. You can set PAGESIZE to zero to suppress all headings, page breaks, titles, the initial blank line, and other formatting information.

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

SET PAUSE is not supported in iSQL*Plus

Allows you to control scrolling of your terminal when running reports. ON causes SQL*Plus to pause at the beginning of each page of report output. You must press [Return] after each pause. The text you enter specifies the text to be displayed each time SQL*Plus pauses. If you enter multiple words, you must enclose text in single quotes.

You can embed terminal-dependent escape sequences in the PAUSE command. These sequences allow you to create inverse video messages or other effects on terminals that support such characteristics.

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

RECSEP tells SQL*Plus where to make the record separation. For example, if you set RECSEP to WRAPPED, SQL*Plus prints a record separator only after wrapped lines. If you set RECSEP to EACH, SQL*Plus prints a record separator following every row. If you set RECSEP to OFF, SQL*Plus does not print a record separator.

SET RECSEPCHAR {_|c}

Defines the character to display or print to separate records. A record separator consists of a single line of the RECSEPCHAR (record separating character) repeated LINESIZE times. The default is a single space.

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

Controls whether to display output (that is, DBMS_OUTPUT.PUT_LINE) of stored procedures or PL/SQL blocks in SQL*Plus. OFF suppresses the output of DBMS_OUTPUT.PUT_LINE; ON displays the output.

SIZE sets the number of bytes of the output that can be buffered within the Oracle8i or Oracle9i database server. The default for n is 2000. n cannot be less than 2000 or greater than 1,000,000.

When WRAPPED is enabled SQL*Plus wraps the server output within the line size specified by SET LINESIZE, beginning new lines when required.

When WORD_WRAPPED is enabled, each line of server output is wrapped within the line size specified by SET LINESIZE. Lines are broken on word boundaries. SQL*Plus left justifies each line, skipping all leading whitespace.

When TRUNCATED is enabled, each line of server output is truncated to the line size specified by SET LINESIZE.

For each FORMAT, every server output line begins on a new output line.

For more information on DBMS_OUTPUT.PUT_LINE, see your Oracle9i Application Developer's Guide - Fundamentals.

Example

To enable text display in a PL/SQL block using DBMS_OUTPUT.PUT_LINE, enter

Keyboard icon
SET SERVEROUTPUT ON

The following example shows what happens when you execute an anonymous procedure with SET SERVEROUTPUT ON:

Keyboard icon
BEGIN DBMS_OUTPUT.PUT_LINE('Task is complete'); END; / Screen icon
Task is complete. PL/SQL procedure successfully completed.

The following example shows what happens when you create a trigger with SET SERVEROUTPUT ON:

Keyboard icon
CREATE TRIGGER SERVER_TRIG BEFORE INSERT OR UPDATE - OR DELETE ON SERVER_TAB BEGIN DBMS_OUTPUT.PUT_LINE('Task is complete.'); END; / Screen icon
Trigger created. Keyboard icon
INSERT INTO SERVER_TAB VALUES ('TEXT'); Screen icon
Task is complete. 1 row created.

To set the output to WORD_WRAPPED, enter

Keyboard icon
SET SERVEROUTPUT ON FORMAT WORD_WRAPPED SET LINESIZE 20 BEGIN DBMS_OUTPUT.PUT_LINE('If there is nothing left to do'); DBMS_OUTPUT.PUT_LINE('shall we continue with plan B?'); END; / Screen icon
If there is nothing left to do shall we continue with plan B?

To set the output to TRUNCATED, enter

Keyboard icon
SET SERVEROUTPUT ON FORMAT TRUNCATED SET LINESIZE 20 BEGIN DBMS_OUTPUT.PUT_LINE('If there is nothing left to do'); DBMS_OUTPUT.PUT_LINE('shall we continue with plan B?'); END; / Screen icon
If there is nothing shall we continue wi

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

SET SHIFTINOUT is not supported in iSQL*Plus

Allows correct alignment for terminals that display shift characters. The SET SHIFTINOUT command is useful for terminals which display shift characters together with data (for example, IBM 3270 terminals). You can only use this command with shift sensitive character sets (for example, JA16DBCS).

Use VISIBLE for terminals that display shift characters as a visible character (for example, a space or a colon). INVISIBLE is the opposite and does not display any shift characters.

Example

To enable the display of shift characters on a terminal that supports them, enter

Keyboard icon
SET SHIFTINOUT VISIBLE SELECT LAST_NAME, JOB_ID FROM EMP_DETAILS_VIEW WHERE SALARY > 12000; Screen icon
LAST_NAME JOB_ID ---------- ---------- :JJOO: :AABBCC: :AA:abc :DDEE:e

where ":" = visible shift character
uppercase represents multibyte characters

lowercase represents singlebyte characters

SET SHOW[MODE] {ON|OFF}

SET SHOWMODE is not supported in iSQL*Plus

Controls whether SQL*Plus lists the old and new settings of a SQL*Plus system variable when you change the setting with SET. ON lists the settings; OFF suppresses the listing. SHOWMODE ON has the same behavior as the obsolete SHOWMODE BOTH.

SET SQLBL[ANKLINES] {ON|OFF}

SET SQLBLANKLINES is not supported in iSQL*Plus

Controls whether SQL*Plus allows blank lines within a SQL command or script. ON interprets blank lines and new lines as part of a SQL command or script. OFF, the default value, does not allow blank lines or new lines in a SQL command or script or script.

Enter the BLOCKTERMINATOR to stop SQL command entry without running the SQL command. Enter the SQLTERMINATOR character to stop SQL command entry and run the SQL statement.

Example

To allow blank lines in a SQL statement, enter

Keyboard icon
SET SQLBLANKLINES ON REM Using the SQLTERMINATOR (default is ";") REM Could have used the BLOCKTERMINATOR (default is ".") SELECT * FROM DUAL ;

The following output results:

Screen icon
D - X

SET SQLC[ASE] {MIX[ED]|LO[WER]|UP[PER]}

Converts the case of SQL commands and PL/SQL blocks just prior to execution. SQL*Plus converts all text within the command, including quoted literals and identifiers, to uppercase if SQLCASE equals UPPER, to lowercase if SQLCASE equals LOWER, and makes no changes if SQLCASE equals MIXED.

SQLCASE does not change the SQL buffer itself.

SET SQLCO[NTINUE] {> |text}

SET SQLCONTINUE is not supported in iSQL*Plus

Sets the character sequence SQL*Plus displays as a prompt after you continue a SQL*Plus command on an additional line using a hyphen (-).

Example

To set the SQL*Plus command continuation prompt to an exclamation point followed by a space, enter

Keyboard icon
SET SQLCONTINUE '! '

SQL*Plus will prompt for continuation as follows:

TTITLE 'MONTHLY INCOME' -
! RIGHT SQL.PNO SKIP 2 -
! CENTER 'PC DIVISION'

The default continuation prompt is "> ".

SET SQLN[UMBER] {ON|OFF}

SET SQLNUMBER is not supported in iSQL*Plus

Sets the prompt for the second and subsequent lines of a SQL command or PL/SQL block. ON sets the prompt to be the line number. OFF sets the prompt to the value of SQLPROMPT.

SET SQLPLUSCOMPAT[IBILITY] {x.y[.z]}

Sets the behavior or output format of VARIABLE to that of the release or version specified by x.y[.z]. Where x is the version number, y is the release number, and z is the update number. For example, 8.1, 8.1.7 or 9.0.0. In later releases, SQLPLUSCOMPATIBILITY may affect features other than VARIABLE.

Setting the value of SQLPLUSCOMPATIBILITY to a version less than 9.0.0 will result in VARIABLE definition of NCHAR or NVARCHAR2 datatypes to revert to Oracle8i behavior whereby the size of the variable is in bytes or characters depending on the chosen national character set.

The default glogin.sql file contains SET SQLPLUSCOMPAT 8.1.7. It is recommended that you add SET SQLPLUSCOMPAT 9.0.0 to your scripts to maximize their compatibility with future versions of SQL*Plus.

SET SQLPRE[FIX] {#|c}

SET SQLPREFIX is not supported in iSQL*Plus

Sets the SQL*Plus prefix character. While you are entering a SQL command or PL/SQL block, you can enter a SQL*Plus command on a separate line, prefixed by the SQL*Plus prefix character. SQL*Plus will execute the command immediately without affecting the SQL command or PL/SQL block that you are entering. The prefix character must be a non-alphanumeric character.

SET SQLP[ROMPT] {SQL>|text}

SET SQLPROMPT is not supported in iSQL*Plus

Sets the SQL*Plus command prompt.

Example

You need the Select Any Table privilege to successfully run the following example scripts.

To change your SQL*Plus prompt to display your username and SID, enter:

Keyboard icon
SET SQLPROMPT '&_CONNECT_IDENTIFIER > '

To change your SQL*Plus prompt to display your SID enter:

Keyboard icon
SET TERMOUT OFF COLUMN X NEW_VALUE Y SELECT RTRIM(INSTANCE, CHR(0)) X FROM V$THREAD; SET SQLPROMPT '&Y SQL>' SET TERMOUT ON

To set the SQL*Plus command prompt to show the current user, enter

Keyboard icon
SET TERMOUT OFF COLUMN D22 NEW_VALUE VAR SELECT USERNAME D22 FROM USER_USERS; SET SQLPROMPT '&&VAR>' SET TERMOUT ON

These settings are not dynamic. You need to reset them whenever you change instances, such as when you use the connect command to log on to another instance.

SET SQLT[ERMINATOR] {;|c|ON|OFF}

Sets the character used to end and execute SQL commands to c. It cannot be an alphanumeric character or a whitespace. OFF means that SQL*Plus recognizes no command terminator; you terminate a SQL command by entering an empty line. If SQLBLANKLINES is set ON, you must use the BLOCKTERMINATOR to terminate a SQL command. ON resets the terminator to the default semicolon (;).

SET SUF[FIX] {SQL|text}

SET SUFFIX is not supported in iSQL*Plus

Sets the default file extension that SQL*Plus uses in commands that refer to scripts. SUFFIX does not control extensions for spool files.

Example

To change the default command-file extension from the default, .SQL to .UFI, enter

Keyboard icon
SET SUFFIX UFI

If you then enter

Keyboard icon
GET EXAMPLE

SQL*Plus will look for a file named EXAMPLE.UFI instead of EXAMPLE.SQL.

SET TAB {ON|OFF}

SET TAB is not supported in iSQL*Plus

Determines how SQL*Plus formats white space in terminal output. OFF uses spaces to format white space in the output. ON uses the TAB character. TAB settings are every eight characters. The default value for TAB is system dependent.

SET TERM[OUT] {ON|OFF}

SET TERMOUT is not supported in iSQL*Plus

Controls the display of output generated by commands executed from a script. OFF suppresses the display so that you can spool output from a script without seeing the output on the screen. ON displays the output. TERMOUT OFF does not affect output from commands you enter interactively.

SET TI[ME] {ON|OFF}

SET TIME is not supported in iSQL*Plus

Controls the display of the current time. ON displays the current time before each command prompt. OFF suppresses the time display.

SET TIMI[NG] {ON|OFF}

Controls the display of timing statistics. ON displays timing statistics on each SQL command or PL/SQL block run. OFF suppresses timing of each command. For information about the data SET TIMING ON displays, see the Oracle installation and user's manual(s) provided for your operating system. Refer to the TIMING command for information on timing multiple commands.

SET TRIM[OUT] {ON|OFF}

SET TRIMOUT is not supported in iSQL*Plus

Determines whether SQL*Plus allows trailing blanks at the end of each displayed line. ON removes blanks at the end of each line, improving performance especially when you access SQL*Plus from a slow communications device. OFF allows SQL*Plus to display trailing blanks. TRIMOUT ON does not affect spooled output.

SET TRIMS[POOL] {ON|OFF}

SET TRIMSPOOL is not supported in iSQL*Plus

Determines whether SQL*Plus allows trailing blanks at the end of each spooled line. ON removes blanks at the end of each line. OFF allows SQL*Plus to include trailing blanks. TRIMSPOOL ON does not affect terminal output.

SET UND[ERLINE] {-|c|ON|OFF}

Sets the character used to underline column headings in reports to c. Note, c cannot be an alphanumeric character or a white space. ON or OFF turns underlining on or off. ON changes the value of c back to the default "-".

SET VER[IFY] {ON|OFF}

Controls whether to list the text of a SQL statement or PL/SQL command before and after replacing substitution variables with values. ON lists the text; OFF suppresses the listing.

SET WRA[P] {ON|OFF}

Controls whether to truncate the display of a selected row if it is too long for the current line width. OFF truncates the selected row; ON allows the selected row to wrap to the next line.

Use the WRAPPED and TRUNCATED clauses of the COLUMN command to override the setting of WRAP for specific columns.

SHOW

SHO[W] option

where option represents one of the following terms or clauses:

system_variable
ALL
BTI[TLE]
ERR[ORS] [ { FUNCTION | PROCEDURE | PACKAGE | PACKAGE BODY | TRIGGER
| VIEW | TYPE | TYPE BODY | DIMENSION | JAVA CLASS } [schema.]name]
LNO
PARAMETERS [parameter_name]
PNO
REL[EASE]
REPF[OOTER]
REPH[EADER]
SGA
SPOO[L]
SQLCODE
TTI[TLE]
USER

Shows the value of a SQL*Plus system variable or the current SQL*Plus environment. SHOW SGA requires a DBA privileged login.

Terms

Refer to the following list for a description of each term or clause:

system_variable

Represents any system variable set by the SET command.

ALL

Lists the settings of all SHOW options, except ERRORS and SGA, in alphabetical order.

BTI[TLE]

Shows the current BTITLE definition.

ERR[ORS] [{FUNCTION|PROCEDURE|PACKAGE|PACKAGE BODY|TRIGGER
|VIEW|TYPE|TYPE BODY | DIMENSION | JAVA CLASS} [schema.]name]

Shows the compilation errors of a stored procedure (includes stored functions, procedures, and packages). After you use the CREATE command to create a stored procedure, a message is displayed if the stored procedure has any compilation errors. To see the errors, you use SHOW ERRORS.

When you specify SHOW ERRORS with no arguments, SQL*Plus shows compilation errors for the most recently created or altered stored procedure. When you specify the type (function, procedure, package, package body, trigger, view, type, type body, dimension, or java class) and the name of the PL/SQL stored procedure, SQL*Plus shows errors for that stored procedure. For more information on compilation errors, see your PL/SQL User's Guide and Reference.

schema contains the named object. If you omit schema, SHOW ERRORS assumes the object is located in your current schema.

SHOW ERRORS output displays the line and column number of the error (LINE/COL) as well as the error itself (ERROR). LINE/COL and ERROR have default widths of 8 and 65, respectively. You can alter these widths using the COLUMN command.

LNO

Shows the current line number (the position in the current page of the display and/or spooled output).

PARAMETERS [parameter_name]

Displays the current values for one or more initialization parameters. You can use a string after the command to see a subset of parameters whose names include that string. For example, if you enter:

Keyboard icon
SHOW PARAMETERS COUNT Screen icon
NAME TYPE VALUE ------------------------------ ----- ----- db_file_multiblock_read_count integer 12 spin_count integer 0

The SHOW PARAMETERS command, without any string following the command, displays all initialization parameters.

Your output may vary depending on the version and configuration of the Oracle database server to which you are connected. You need SELECT ON V_$PARAMETER object privileges to use the PARAMETERS clause, otherwise you will receive a message

ORA-00942: table or view does not exist

PNO

Shows the current page number.

REL[EASE]

Shows the release number of Oracle that SQL*Plus is accessing.

REPF[OOTER]

Shows the current REPFOOTER definition.

REPH[EADER]

Shows the current REPHEADER definition.

SPOO[L]

Shows whether output is being spooled.

SGA

Displays information about the current instance's System Global Area. Note, you need SELECT ON V_$SGA object privileges to use the SGA clause, otherwise you will receive a message

ORA-00942: table or view does not exist

SQLCODE

Shows the value of SQL.SQLCODE (the SQL return code of the most recent operation).

TTI[TLE]

Shows the current TTITLE definition.

USER

Shows the username you are currently using to access SQL*Plus. If you connect as "/ AS SYSDBA", then the SHOW USER command displays

USER is "SYS"

Examples

To list the current LINESIZE, enter

Keyboard icon
SHOW LINESIZE

If the current linesize is 80 characters, SQL*Plus will give the following response:

Screen icon
LINESIZE 80

The following example illustrates how to create a stored procedure and then show its compilation errors:

Keyboard icon
CONNECT SYSTEM/MANAGER CREATE PROCEDURE HR.PROC1 AS BEGIN :P1 := 1; END; / Screen icon
Warning: Procedure created with compilation errors. Keyboard iconScreen icon
SHOW ERRORS PROCEDURE PROC1 NO ERRORS. SHOW ERRORS PROCEDURE HR.PROC1 Errors for PROCEDURE HR.PROC1: LINE/COL ERROR -------------------------------------------------------- 3/3 PLS-00049: bad bind variable 'P1'

To show whether AUTORECOVERY is enabled, enter

Keyboard icon
SHOW AUTORECOVERY Screen icon
AUTORECOVERY ON

To display the connect identifier for the default instance, enter

Keyboard icon
SHOW INSTANCE Screen icon
INSTANCE "LOCAL"

To display the location for archive logs, enter

Keyboard icon
SHOW LOGSOURCE Screen icon
LOGSOURCE "/usr/oracle90/dbs/arch"

To display information about the SGA, enter

Keyboard icon
SHOW SGA Screen icon
Total System Global Area 7629732 bytes Fixed Size 60324 bytes Variable Size 6627328 bytes Database Buffers 409600 bytes Redo Buffers 532480 bytes

SHUTDOWN

SHUTDOWN [ABORT|IMMEDIATE|NORMAL|TRANSACTIONAL [LOCAL]]

Shuts down a currently running Oracle instance, optionally closing and dismounting a database.

Terms

Refer to the following list for a description of each term or clause:

ABORT

Proceeds with the fastest possible shutdown of the database without waiting for calls to complete or users to disconnect.

Uncommitted transactions are not rolled back. Client SQL statements currently being processed are terminated. All users currently connected to the database are implicitly disconnected and the next database startup will require instance recovery.

You must use this option if a background process terminates abnormally.

IMMEDIATE

Does not wait for current calls to complete or users to disconnect from the database.

Further connects are prohibited. The database is closed and dismounted. The instance is shutdown and no instance recovery is required on the next database startup.

NORMAL

NORMAL is the default option which waits for users to disconnect from the database.

Further connects are prohibited. The database is closed and dismounted. The instance is shutdown and no instance recovery is required on the next database startup.

TRANSACTIONAL [LOCAL]

Performs a planned shutdown of an instance while allowing active transactions to complete first. It prevents clients from losing work without requiring all users to log off.

No client can start a new transaction on this instance. Attempting to start a new transaction results in disconnection. After completion of all transactions, any client still connected to the instance is disconnected. Now the instance shuts down just as it would if a SHUTDOWN IMMEDIATE statement was submitted. The next startup of the database will not require any instance recovery procedures.

The LOCAL mode specifies a transactional shutdown on the local instance only, so that it only waits on local transactions to complete, not all transactions. This is useful, for example, for scheduled outage maintenance.

Usage

SHUTDOWN with no arguments is equivalent to SHUTDOWN NORMAL.

You must be connected to a database as SYSOPER, or SYSDBA. You cannot connect via a multi-threaded server. For more information about connecting to a database, see the CONNECT command earlier in this chapter.

Examples

To shutdown the database in normal mode, enter

Keyboard icon
SHUTDOWN Screen icon
Database closed. Database dismounted. Oracle instance shut down.

SPOOL

SPOOL is not available in iSQL*Plus. Use preference settings to output to a file.

SPO[OL] [file_name[.ext]|OFF|OUT]

Stores query results in a file, or optionally sends the file to a printer.

Terms

Refer to the following list for a description of each term or clause:

file_name[.ext]

Represents the name of the file to which you wish to spool. SPOOL followed by file_name begins spooling displayed output to the named file. If you do not specify an extension, SPOOL uses a default extension (LST or LIS on most systems).

OFF

Stops spooling.

OUT

Stops spooling and sends the file to your host computer's standard (default) printer. This option is not available on some operating systems.

Enter SPOOL with no clauses to list the current spooling status.

Usage

To spool output generated by commands in a script without displaying the output on the screen, use SET TERMOUT OFF. SET TERMOUT OFF does not affect output from commands run interactively.

Examples

To record your output in the file DIARY using the default file extension, enter

Keyboard icon
SPOOL DIARY

To stop spooling and print the file on your default printer, enter

Keyboard icon
SPOOL OUT

START

STA[RT] {url|file_name[.ext] } [arg...]

Runs the SQL*Plus statements in the specified script. The script can be called from a web server in iSQL*Plus, or from the local file system or a web server in SQL*Plus command-line. You can pass values to script variables in the usual way.

Terms

Refer to the following list for a description of each term or clause:

url

Specifies the Uniform Resource Locator of a script to run on the specified web server. SQL*Plus supports HTTP, FTP and gopher protocols.

file_name[.ext]

The script you wish to execute. The file can contain any command that you can run interactively.

If you do not specify an extension, SQL*Plus assumes the default command-file extension (normally SQL). For information on changing this default extension, see the SUFFIX variable of the SET command in this chapter.

When you enter START file_name.ext, SQL*Plus searches for a file with the filename and extension you specify in the current default directory. If SQL*Plus does not find such a file, SQL*Plus will search a system-dependent path to find the file. Some operating systems may not support the path search. Consult the Oracle installation and user's manual(s) provided for your operating system for specific information related to your operating system environment.

arg ...

Data items you wish to pass to parameters in the script. If you enter one or more arguments, SQL*Plus substitutes the values into the parameters (&1, &2, and so forth) in the script. The first argument replaces each occurrence of &1, the second replaces each occurrence of &2, and so on.

The START command DEFINEs the parameters with the values of the arguments; if you START the script again in this session, you can enter new arguments or omit the arguments to use the old values.

For more information on using parameters, refer to the subsection "Substitution Variables in iSQL*Plus" under "Writing Interactive Commands".

Usage

All previous settings like COLUMN command settings stay in effect when the script starts. If the script changes any setting, then this new value stays in effect after the script has finished

The @ ("at" sign) and @@ (double "at" sign) commands function similarly to START. Disabling the START command in the Product User Profile (see ""Disabling SQL*Plus, SQL, and PL/SQL Commands"), also disables the @ and @@ commands. See the @ ("at" sign) and @@ (double "at" sign) commands in this chapter for further information on these commands.

The EXIT or QUIT command in a script terminates SQL*Plus.

Examples

A file named PROMOTE with the extension SQL, used to promote employees, might contain the following command:

Keyboard icon
SELECT FIRST_NAME, LAST_NAME, JOB_ID, SALARY FROM EMP_DETAILS_VIEW WHERE JOB_ID='&1' AND SALARY>&2;

To run this script, enter

Keyboard icon
START PROMOTE ST_MAN 7000

or if it is located on a web server, enter a command in the form:

Keyboard icon
START HTTP://machine_name.domain:port/PROMOTE.SQL ST_MAN 7000

Where machine_name.domain must be replaced by the host.domain name, and port by the port number used by the web server where the script is located.

The following command is executed:

SELECT LAST_NAME, LAST_NAME
FROM EMP_DETAILS_VIEW
WHERE JOB_ID='ST_MAN' AND SALARY>7000;

and the results displayed.

STARTUP

STARTUP options | migrate_options

where options has the following syntax:

[FORCE] [RESTRICT] [PFILE=filename] [QUIET] [ MOUNT [dbname] |
[ OPEN [open_options] [dbname] ] |
NOMOUNT ]

where open_options has the following syntax:

READ {ONLY | WRITE [RECOVER]} | RECOVER

and where migrate_options has the following syntax:

[PFILE=filename] MIGRATE [QUIET]

Starts an Oracle instance with several options, including mounting and opening a database.

Terms

Refer to the following list for a description of each term and clause:

FORCE

Shuts down the current Oracle instance (if it is running) with SHUTDOWN mode ABORT, before restarting it. If the current instance is running and FORCE is not specified, an error results. FORCE is useful while debugging and under abnormal circumstances. It should not normally be used.

RESTRICT

Only allows Oracle users with the RESTRICTED SESSION system privilege to connect to the database. Later, you can use the ALTER SYSTEM command to disable the restricted session feature.

PFILE=filename

Causes the specified parameter file to be used while starting up the instance. If PFILE is not specified, then the default STARTUP parameter file is used. The default file used is platform specific. For example, the default file is $ORACLE_HOME/dbs/init$ORACLE_SID.ora on UNIX, and %ORACLE_HOME%\database\initORCL.ora on Windows.

QUIET

Suppresses the display of System Global Area information for the starting instance.

MOUNT dbname

Mounts a database but does not open it.

dbname is the name of the database to mount or open. If no database name is specified, the database name is taken from the initialization parameter DB_NAME.

OPEN

Mounts and opens the specified database.

NOMOUNT

Causes the database not to be mounted upon instance startup.

Cannot be used with MOUNT, or OPEN.

RECOVER

Specifies that media recovery should be performed, if necessary, before starting the instance. STARTUP RECOVER has the same effect as issuing the RECOVER DATABASE command and starting an instance. Only complete recovery is possible with the RECOVER option.

Recovery proceeds, if necessary, as if AUTORECOVERY is set to ON, regardless of whether or not AUTORECOVERY is enabled. If a redo log file is not found in the expected location, recovery continues as if AUTORECOVERY is disabled, by prompting you with the suggested location and name of the subsequent log files that need to be applied.

MIGRATE

Starts the database in OPEN MIGRATE mode and sets system initialization parameters to specific values required to enable database upgrade or downgrade scripts to be run. MIGRATE should only be used when a database is first started with a new version of the Oracle Database Server.

See the Oracle9i Database Migration guide for details about preparing for, testing and implementing a database version migration or release upgrade or downgrade.

When run, upgrade or downgrade scripts transform an installed version or release of an Oracle database into another version, for example, to migrate an Oracle7 database to an Oracle9i database. Once the migration completes, the database should be shut down and restarted normally.

Usage

You must be connected to a database as SYSOPER, or SYSDBA. You cannot be connected via a multi-threaded server.

STARTUP with no arguments is equivalent to STARTUP OPEN.

STARTUP OPEN RECOVER mounts and opens the database even when recovery fails.

Examples

To start an instance using the standard parameter file, mount the default database, and open the database, enter

Keyboard icon
STARTUP

or enter

Keyboard icon
STARTUP OPEN database

To start an instance using the standard parameter file, mount the default database, and open the database, enter

Keyboard icon
STARTUP FORCE RESTRICT MOUNT

To start an instance using the parameter file TESTPARM without mounting the database, enter

Keyboard icon
STARTUP PFILE=testparm NOMOUNT

To shutdown a particular database, immediately restart and open it, allow access only to database administrators, and use the parameter file MYINIT.ORA. enter

Keyboard icon
STARTUP FORCE RESTRICT PFILE=myinit.ora OPEN database

To startup an instance and mount but not open a database, enter

Keyboard icon
CONNECT / as SYSDBA Screen icon
Connected to an idle instance. Keyboard icon
STARTUP MOUNT Screen icon
ORACLE instance started. Total System Global Area 7629732 bytes Fixed Size 60324 bytes Variable Size 6627328 bytes Database Buffers 409600 bytes Redo Buffers 532480 bytes

STORE

STORE is not available in iSQL*Plus.

STORE SET file_name[.ext] [CRE[ATE]|REP[LACE]|APP[END]]

Saves attributes of the current SQL*Plus environment in a host operating system script.

Terms

Refer to the following list for a description of each term or clause:

SET

Saves the values of the system variables.

Refer to the SAVE command for information on the other terms and clauses in the STORE command syntax.

Usage

This command creates a script which can be executed with the START, @ or @@ commands.

If you want to store a file under a name identical to a STORE command clause (that is, CREATE, REPLACE or APPEND), you must put the name in single quotes or specify a file extension.

Examples

To store the current SQL*Plus system variables in a file named DEFAULTENV with the default command-file extension, enter

Keyboard icon
STORE SET DEFAULTENV

To append the current SQL*Plus system variables to an existing file called DEFAULTENV with the extension OLD, enter

Keyboard icon
STORE SET DEFAULTENV.OLD APPEND

TIMING

TIMI[NG] [START text|SHOW|STOP]

Records timing data for an elapsed period of time, lists the current timer's name and timing data, or lists the number of active timers.

Terms

Refer to the following list for a description of each term or clause:

START text

Sets up a timer and makes text the name of the timer. You can have more than one active timer by STARTing additional timers before STOPping the first; SQL*Plus nests each new timer within the preceding one. The timer most recently STARTed becomes the current timer.

SHOW

Lists the current timer's name and timing data.

STOP

Lists the current timer's name and timing data, then deletes the timer. If any other timers are active, the next most recently STARTed timer becomes the current timer.

Enter TIMING with no clauses to list the number of active timers. For other information about TIMING, see SET AUTOTRACE

Usage

You can use this data to do a performance analysis on any commands or blocks run during the period.

For information about the data TIMING displays, see the Oracle installation and user's manual(s) provided for your operating system. Refer to the SET TIMING command for information on automatically displaying timing data after each SQL command or PL/SQL block you run.

To delete all timers, use the CLEAR TIMING command.

Examples

To create a timer named SQL_TIMER, enter

Keyboard icon
TIMING START SQL_TIMER

To list the current timer's title and accumulated time, enter

Keyboard icon
TIMING SHOW

To list the current timer's title and accumulated time and to remove the timer, enter

Keyboard icon
TIMING STOP

TTITLE

TTI[TLE] [printspec [text|variable] ...] [ON|OFF]

where printspec represents one or more of the following clauses used to place and format the text:

COL n

CE[NTER]

S[KIP] [n]

R[IGHT]

TAB n

BOLD

LE[FT]

FORMAT text

Places and formats a specified title at the top of each report page or lists the current TTITLE definition. The old form of TTITLE is used if only a single word or string in quotes follows the TTITLE command.

For a description of the old form of TTITLE, see TTITLE.

Terms

Refer to the following list for a description of each term or clause. These terms and clauses also apply to the BTITLE command.

text

The title text. Enter text in single quotes if you want to place more than one word on a single line.

variable

A user variable or any of the following system-maintained values, SQL.LNO (the current line number), SQL.PNO (the current page number), SQL.RELEASE (the current Oracle release number), SQL.SQLCODE (the current error code), or SQL.USER (the current username).

To print one of these values, reference the appropriate variable in the title. You can format variable with the FORMAT clause.

OFF

Turns the title off (suppresses its display) without affecting its definition.

ON

Turns the title on (restores its display). When you define a top title, SQL*Plus automatically sets TTITLE to ON.

COL n

Indents to column n of the current line (backward if column n has been passed). Here "column" means print position, not table column.

S[KIP] [n]

Skips to the start of a new line n times; if you omit n, one time; if you enter zero for n, backward to the start of the current line.

TAB n

Skips forward n columns (backward if you enter a negative value for n). "Column" in this context means print position, not table column.

LE[FT]|CE[NTER]|R[IGHT]

Left-align, center, and right-align data on the current line respectively. SQL*Plus aligns following data items as a group, up to the end of the printspec or the next LEFT, CENTER, RIGHT, or COL command. CENTER and RIGHT use the SET LINESIZE value to calculate the position of the data item that follows.

BOLD

Prints data in bold print. SQL*Plus represents bold print on your terminal by repeating the data on three consecutive lines. On some operating systems, SQL*Plus may instruct your printer to print bold text on three consecutive lines, instead of bold.

FORMAT text

Specifies a format model that determines the format of following data items, up to the next FORMAT clause or the end of the command. The format model must be a text constant such as A10 or $999. See the COLUMN FORMAT command for more information on formatting and valid format models.

If the datatype of the format model does not match the datatype of a given data item, the FORMAT clause has no effect on that item.

If no appropriate FORMAT model precedes a given data item, SQL*Plus prints NUMBER values using the format specified by SET NUMFORMAT or, if you have not used SET NUMFORMAT, the default format. SQL*Plus prints DATE values according to the default format.

Refer to the FORMAT clause of the COLUMN command in this chapter for more information on default formats.

Enter TTITLE with no clauses to list the current TTITLE definition.

Usage

If you do not enter a printspec clause before the first occurrence of text, TTITLE left justifies the text. SQL*Plus interprets TTITLE in the new form if a valid printspec clause (LEFT, SKIP, COL, and so on) immediately follows the command name.

See COLUMN NEW_VALUE for information on printing column and DATE values in the top title.

You can use any number of constants and variables in a printspec. SQL*Plus displays them in the order you specify them, positioning and formatting each constant or variable as specified by the printspec clauses that precede it.

The length of the title you specify with TTITLE cannot exceed 2400 characters.

The continuation character (a hyphen) will not be recognized inside a single-quoted title text string. To be recognized, the continuation character must appear outside the quotes, as follows:

TTITLE CENTER 'Summary Report for' -
> 'the Month of May'

Examples

To define "Monthly Analysis" as the top title and to left-align it, to center the date, to right-align the page number with a three-digit format, and to display "Data in Thousands" in the center of the next line, enter

Keyboard icon
TTITLE LEFT 'Monthly Analysis' CENTER '01 Jan 2001' - RIGHT 'Page:' FORMAT 999 SQL.PNO SKIP CENTER - 'Data in Thousands' Screen icon
Monthly Analysis 01 Jan 2001 Page: 1 Data in Thousands

To suppress the top title display without changing its definition, enter

Keyboard icon
TTITLE OFF

UNDEFINE

UNDEF[INE] variable ...

Deletes one or more user variables that you defined either explicitly (with the DEFINE command) or implicitly (with an argument to the START command).

Terms

Refer to the following for a description of the term or clause:

variable

Represents the name of the user variable you wish to delete. One or more user variables may be deleted in the same command.

Examples

To undefine a user variable named POS, enter

Keyboard icon
UNDEFINE POS

To undefine two user variables named MYVAR1 and MYVAR2, enter

Keyboard icon
UNDEFINE MYVAR1 MYVAR2

VARIABLE

VAR[IABLE] [variable [NUMBER|CHAR|CHAR (n [CHAR|BYTE])|NCHAR|NCHAR (n)
|VARCHAR2 (n [CHAR|BYTE])|NVARCHAR2 (n)|CLOB|NCLOB|REFCURSOR]]

Declares a bind variable that can be referenced in PL/SQL. For more information on bind variables, see "Using Bind Variables". For more information about PL/SQL, see your PL/SQL User's Guide and Reference.

VARIABLE without arguments displays a list of all the variables declared in the session. VARIABLE followed only by a variable name lists that variable.

Terms

Refer to the following list for a description of each term or clause:

variable

Represents the name of the bind variable you wish to create.

NUMBER

Creates a variable of type NUMBER with fixed length.

CHAR

Creates a variable of type CHAR (character) with length one.

CHAR (n[CHAR|BYTE])

Creates a variable of type CHAR with length n bytes or n characters. The maximum that n can be is 2000 bytes, and the minimum is 1 byte or 1 character. The maximum n for a CHAR variable with character semantics is determined by the number of bytes required to store each character for the chosen character set, with an upper limit of 2000 bytes. The length semantics are determined by the length qualifiers CHAR or BYTE, and if not explicitly stated, the value of the NLS_LENGTH_SEMANTICS environment variable is applied to the bind variable. Explicitly stating the length semantics at variable definition stage will always take precedence over the NLS_LENGTH_SEMANTICS setting.

NCHAR

Creates a variable of type NCHAR (national character) with length one.

NCHAR (n)

Creates a variable of type NCHAR with length n characters. The maximum that n can be is determined by the number of bytes required to store each character for the chosen national character set, with an upper limit of 2000 bytes. The only exception to this is when a SQL*Plus session is connected to a pre Oracle9i server, or the SQLPLUSCOMPATIBILITY system variable is set to a version less than 9.0.0. In this case the length n can be in bytes or characters depending on the chosen national character set, with the upper limit of 2000 bytes still retained.

VARCHAR2 (n[CHAR|BYTE])

Creates a variable of type VARCHAR2 with length of up to n bytes or n characters. The maximum that n can be is 4000 bytes, and the minimum is 1 byte or 1 character. The maximum n for a VARCHAR2 variable with character semantics is determined by the number of bytes required to store each character for the chosen character set, with an upper limit of 4000 bytes. The length semantics are determined by the length qualifiers CHAR or BYTE, and if not explicitly stated, the value of the NLS_LENGTH_SEMANTICS environment variable is applied to the bind variable. Explicitly stating the length semantics at variable definition stage will always take precedence over the NLS_LENGTH_SEMANTICS setting.

NVARCHAR2 (n)

Creates a variable of type NVARCHAR2 with length of up to n characters. The maximum that n can be is determined by the number of bytes required to store each character for the chosen national character set, with an upper limit of 4000 bytes. The only exception to this is when a SQL*Plus session is connected to a pre Oracle9i server, or the SQLPLUSCOMPATIBILITY system variable is set to a version less than 9.0.0. In this case the length n can be in bytes or characters depending on the chosen national character set, with the upper limit of 4000 bytes still retained.

CLOB

Creates a variable of type CLOB.

NCLOB

Creates a variable of type NCLOB.

REFCURSOR

Creates a variable of type REF CURSOR.

Usage

Bind variables may be used as parameters to stored procedures, or may be directly referenced in anonymous PL/SQL blocks.

To display the value of a bind variable created with VARIABLE, use the PRINT command. For more information, see the PRINT command in this chapter.

To automatically display the value of a bind variable created with VARIABLE, use the SET AUTOPRINT command. For more information, see the SET AUTOPRINT command in this chapter.

Bind variables cannot be used in the COPY command or SQL statements, except in PL/SQL blocks. Instead, use substitution variables.

When you execute a VARIABLE ... CLOB or NCLOB command, SQL*Plus associates a LOB locator with the bind variable. The LOB locator is automatically populated when you execute a SELECT clob_column INTO :cv statement in a PL/SQL block. SQL*Plus closes the LOB locator after completing a PRINT statement for that bind variable, or when you exit SQL*Plus.

SQL*Plus SET commands such as SET LONG and SET LONGCHUNKSIZE and SET LOBOFFSET may be used to control the size of the buffer while PRINTing CLOB or NCLOB bind variables.

SQL*Plus REFCURSOR bind variables may be used to reference PL/SQL 2.3 or higher Cursor Variables, allowing PL/SQL output to be formatted by SQL*Plus. For more information on PL/SQL Cursor Variables, see your PL/SQL User's Guide and Reference.

When you execute a VARIABLE ... REFCURSOR command, SQL*Plus creates a cursor bind variable. The cursor is automatically opened by an OPEN ... FOR SELECT statement referencing the bind variable in a PL/SQL block. SQL*Plus closes the cursor after completing a PRINT statement for that bind variable, or on exit.

SQL*Plus formatting commands such as BREAK, COLUMN, COMPUTE and SET may be used to format the output from PRINTing a REFCURSOR.

A REFCURSOR bind variable may not be PRINTed more than once without re-executing the PL/SQL OPEN ... FOR statement.

Examples

The following example illustrates creating a bind variable and then setting it to the value returned by a function:

Keyboard icon
VARIABLE id NUMBER BEGIN :id := EMP_MANAGEMENT.HIRE ('BLAKE','MANAGER','KING',2990,'SALES'); END; /

The value returned by the stored procedure is being placed in the bind variable, :id. It can be displayed with the PRINT command or used in subsequent PL/SQL subprograms.

The following example illustrates automatically displaying a bind variable:

Keyboard icon
SET AUTOPRINT ON VARIABLE a REFCURSOR BEGIN OPEN :a FOR SELECT LAST_NAME, CITY, DEPARTMENT_ID FROM EMP_DETAILS_VIEW WHERE SALARY > 12000 ORDER BY DEPARTMENT_ID; END; / Screen icon
PL/SQL procedure successfully completed. LAST_NAME CITY DEPARTMENT_ID ------------------------- ------------------------------ ------------- Hartstein Toronto 20 Russell Oxford 80 Partners Oxford 80 King Seattle 90 Kochhar Seattle 90 De Haan Seattle 90 6 rows selected.

In the above example, there is no need to issue a PRINT command to display the variable.

The following example creates some variables:

Keyboard icon
VARIABLE id NUMBER VARIABLE txt CHAR (20) VARIABLE myvar REFCURSOR

Enter VARIABLE with no arguments to list the defined variables:

Keyboard icon
VARIABLE Screen icon
variable id datatype NUMBER variable txt datatype CHAR(20) variable myvar datatype REFCURSOR

The following example lists a single variable:

Keyboard icon
VARIABLE txt Screen icon
variable txt datatype CHAR(20)

The following example illustrates producing a report listing individual salaries and computing the departmental salary cost for employees who earn more than $12,000 per month:

Keyboard icon
VARIABLE rc REFCURSOR BEGIN OPEN :rc FOR SELECT DEPARTMENT_NAME, LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE SALARY > 12000 ORDER BY DEPARTMENT_NAME, LAST_NAME; END; / Screen icon
PL/SQL procedure successfully completed. Keyboard icon
SET PAGESIZE 100 FEEDBACK OFF TTITLE LEFT '*** Departmental Salary Bill ***' SKIP 2 COLUMN SALARY FORMAT $999,990.99 HEADING 'Salary' COLUMN DEPARTMENT_NAME HEADING 'Department' COLUMN LAST_NAME HEADING 'Employee' COMPUTE SUM LABEL 'Subtotal:' OF SALARY ON DEPARTMENT_NAME COMPUTE SUM LABEL 'Total:' OF SALARY ON REPORT BREAK ON DEPARTMENT_NAME SKIP 1 ON REPORT SKIP 1 PRINT rc Screen icon
*** Departmental Salary Bill *** DEPARTMENT_NAME Employee Salary ------------------------------ ------------------------- ------------ Executive De Haan $17,000.00 King $24,000.00 Kochhar $17,000.00 ****************************** ------------ Subtotal: $58,000.00 Marketing Hartstein $13,000.00 ****************************** ------------ Subtotal: $13,000.00 Sales Partners $13,500.00 Russell $14,000.00 ****************************** ------------ Subtotal: $27,500.00 ------------ Total: $98,500.00

The following example illustrates producing a report containing a CLOB column, and then displaying it with the SET LOBOFFSET command.

Assume you have already created a table named clob_tab which contains a column named clob_col of type CLOB. The clob_col contains the following data:

Remember to run the Departmental Salary Bill report each month. This report 
contains confidential information.

To produce a report listing the data in the col_clob column, enter

Keyboard icon
VARIABLE T CLOB BEGIN SELECT CLOB_COL INTO :T FROM CLOB_TAB; END; / Screen icon
PL/SQL PROCEDURE SUCCESSFULLY COMPLETED

To print 200 characters from the column clob_col, enter

Keyboard icon
SET LINESIZE 70 SET LONG 200 PRINT T Screen icon
T ---------------------------------------------------------------------- Remember to run the Departmental Salary Bill report each month. This r eport contains confidential information.

To set the printing position to the 21st character, enter

Keyboard icon
SET LOBOFFSET 21 PRINT T Screen icon
T ---------------------------------------------------------------------- Departmental Salary Bill report each month. This report contains confi dential information.

For more information on creating CLOB columns, see your Oracle9i SQL Reference.

WHENEVER OSERROR

WHENEVER OSERROR
{EXIT [SUCCESS|FAILURE|n|variable|:BindVariable] [COMMIT|ROLLBACK]
|CONTINUE [COMMIT|ROLLBACK|NONE]}

Performs the specified action (exits SQL*Plus by default) if an operating system error occurs (such as a file writing error).

In iSQL*Plus, performs the specified action (stops the current script by default) and returns focus to the Input area if an operating system error occurs.

Terms

Refer to the following list for a description of each term or clause:

[SUCCESS|FAILURE|n|variable|:BindVariable]

Directs SQL*Plus to perform the specified action as soon as an operating system error is detected. You can also specify that SQL*Plus return a success or failure code, the operating system failure code, or a number or variable of your choice.

EXIT [SUCCESS|FAILURE|n|variable|:BindVariable]

Directs SQL*Plus to exit as soon as an operating system error is detected. You can also specify that SQL*Plus return a success or failure code, the operating system failure code, or a number or variable of your choice. See EXIT in this chapter for details.

CONTINUE

Turns off the EXIT option.

COMMIT

Directs SQL*Plus to execute a COMMIT before exiting or continuing and save pending changes to the database.

ROLLBACK

Directs SQL*Plus to execute a ROLLBACK before exiting or continuing and abandon pending changes to the database.

NONE

Directs SQL*Plus to take no action before continuing.

Usage

If you do not enter the WHENEVER OSERROR command, the default behavior of SQL*Plus is to continue and take no action when an operating system error occurs.

If you do not enter the WHENEVER SQLERROR command, the default behavior of SQL*Plus is to continue and take no action when a SQL error occurs.

Examples

The commands in the following script cause SQL*Plus to exit and COMMIT any pending changes if a failure occurs when reading from the output file:

Keyboard icon
WHENEVER OSERROR EXIT START no_such_file Screen icon
OS Message: No such file or directory Disconnected from Oracle......

WHENEVER SQLERROR

WHENEVER SQLERROR
{EXIT [SUCCESS|FAILURE|WARNING|n|variable|:BindVariable]
[COMMIT|ROLLBACK]|CONTINUE [COMMIT|ROLLBACK|NONE]}

Performs the specified action (exits SQL*Plus by default) if a SQL command or PL/SQL block generates an error.

In iSQL*Plus, performs the specified action (stops the current script by default) and returns focus to the Input area if a SQL command or PL/SQL block generates an error.

Terms

Refer to the following list for a description of each term or clause:

[SUCCESS|FAILURE|WARNING|n|variable|:BindVariable]

Directs SQL*Plus to perform the specified action as soon as it detects a SQL command or PL/SQL block error (but after printing the error message). SQL*Plus will not exit on a SQL*Plus error.

EXIT [SUCCESS|FAILURE|WARNING|n|variable|:BindVariable]

Directs SQL*Plus to exit as soon as it detects a SQL command or PL/SQL block error (but after printing the error message). SQL*Plus will not exit on a SQL*Plus error. The EXIT clause of WHENEVER SQLERROR follows the same syntax as the EXIT command. See EXIT in this chapter for details.

CONTINUE

Turns off the EXIT option.

COMMIT

Directs SQL*Plus to execute a COMMIT before exiting or continuing and save pending changes to the database.

ROLLBACK

Directs SQL*Plus to execute a ROLLBACK before exiting or continuing and abandon pending changes to the database.

NONE

Directs SQL*Plus to take no action before continuing.

Usage

The WHENEVER SQLERROR command is triggered by SQL command or PL/SQL block errors, and not by SQL*Plus command errors.

Examples

The commands in the following script cause iSQL*Plus to stop processing the current script and return focus to the Input area on the Work screen:

The commands in the following script cause SQL*Plus to exit and return the SQL error code if the SQL UPDATE command fails:

Keyboard icon
WHENEVER SQLERROR EXIT SQL.SQLCODE UPDATE EMP_DETAILS_VIEW SET SALARY = SALARY*1.1

The following SQL command error causes iSQL*Plus to stop processing the current script and return focus to the Input area on the Work screen:

Keyboard icon
WHENEVER SQLERROR EXIT SQL.SQLCODE select column_does_not_exiSt from dual; Screen icon
select column_does_not_exist from dual * ERROR at line 1: ORA-00904: invalid column name Disconnected from Oracle.....

The following examples show that the WHENEVER SQLERROR command is not executed after errors with SQL*Plus commands, but it is executed if SQL commands or PL/SQL blocks cause errors:

Keyboard icon
WHENEVER SQLERROR EXIT SQL.SQLCODE column LAST_name headIing "Employee Name" Screen icon
Unknown COLUMN option "headiing" Keyboard icon
SHOW non_existed_option

The following PL/SQL block error causes SQL*Plus to exit and return the SQL error code:

Keyboard icon
WHENEVER SQLERROR EXIT SQL.SQLCODE begin SELECT COLUMN_DOES_NOT_EXIST FROM DUAL; END; / Screen icon
SELECT COLUMN_DOES_NOT_EXIST FROM DUAL; * ERROR at line 2: ORA-06550: line 2, column 10: PLS-00201: identifier 'COLUMN_DOES_NOT_EXIST' must be declared ORA-06550: line 2, column 3: PL/SQL: SQL Statement ignored Disconnected from Oracle.....

Go to previous page Go to next page
Oracle
Copyright © 1996, 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback