PK
DAoa, mimetypeapplication/epub+zipPK DA iTunesMetadata.plistI
Command | Description |
---|---|
| Runs SQL*Plus statements in the specified script. The script can be called from the local file system or from a web server. |
| 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 calling script. |
| Executes the SQL command or PL/SQL block. |
| Reads a line of input and stores it in a given substitution variable. |
| Adds specified text to the end of the current line in the buffer. |
| Displays information about redo log files. |
| 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. |
| Specifies where and how formatting will change in a report, or lists the current break definition. |
| Places and formats a specified title at the bottom of each report page, or lists the current BTITLE definition. |
| Changes text on the current line in the buffer. |
| Resets or erases the current clause or setting for the specified option, such as BREAKS or COLUMNS. |
| Specifies display characteristics for a given column, or lists the current display characteristics for a single column or for all columns. |
| Calculates and prints summary lines, using various standard computations, on subsets of selected rows, or lists all COMPUTE definitions. |
| Connects a given user to Oracle Database. |
| Copies results from a query to a table in the same or another database. |
| Specifies a substitution variable and assigns it a CHAR value, or lists the value and variable type of a single variable or all variables. |
| Deletes one more lines of the buffer. |
| Lists the column definitions for the specified table, view, or synonym or the specifications for the specified function procedure. |
| Commits pending changes to the database and logs the current user off Oracle Database, but does not exit SQL*Plus. |
| Invokes an operating system text editor on the contents of the specified file or on the contents of the buffer. |
| Executes a single PL/SQL statement. |
| Terminates SQL*Plus and returns control to the operating system. |
| Loads an operating system file into the buffer. |
| Accesses the SQL*Plus command-line help system. |
| Executes an operating system command without leaving SQL*Plus. |
| Adds one or more new lines after the current line in the buffer. |
| Lists one or more lines of the buffer. |
| Enables a password to be changed without echoing the password on an input device. |
| Displays the specified text, then waits for the user to press Return. |
| Displays the current value of a bind variable. |
| Sends the specified message to the user's screen. |
| Terminates SQL*Plus and returns control to the operating system QUIT is identical to EXIT. |
| Performs media recovery on one or more tablespaces, one or more datafiles, or the entire database. |
| Begins a comment in a script. |
| Places and formats a specified report footer at the bottom of each report, or lists the current REPFOOTER definition. |
| Places and formats a specified report header at the top of each report, or lists the current REPHEADER definition. |
| Lists and runs the SQL command or PL/SQL block currently stored in the SQL buffer. |
| Saves the contents of the buffer in an operating system file (a script). |
| Sets a system variable to alter the SQL*Plus environment for your current session. |
| Shows the value of a SQL*Plus system variable or the current SQL*Plus environment. |
| Shuts down a currently running Oracle Database instance. |
| Stores query results in an operating system file and, optionally, sends the file to a printer. |
| Runs the SQL statements in the specified script. The script can be called from a local file system or a web server in SQL*Plus command-line. |
| Starts an Oracle Database instance and optionally mounts and opens a database. |
| Saves attributes of the current SQL*Plus environment in an operating system script. |
| 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. |
| Places and formats a specified title at the top of each report page, or lists the current TTITLE definition. |
| Deletes one or more substitution variables that you defined either explicitly (with the DEFINE command) or implicitly (with an argument to the START command). |
| Declares a bind variable that can be referenced in PL/SQL. |
| Exits SQL*Plus if an operating system command generates an error. |
| Exits SQL*Plus if a SQL command or PL/SQL block generates an error. |
| Runs an XQuery 1.0 statement. |
Syntax
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 nS[KIP] [n]TAB nLE[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.
Enter REPHEADER with no clauses to list the current REPHEADER definition.
Terms
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 substitution 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 Database 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 use the FORMAT clause to format variable.
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 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.
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:
REPHEADER PAGE CENTER 'EMPLOYEE LISTING REPORT' TTITLE RIGHT 'Page: ' FORMAT 999 SQL.PNO SELECT LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE SALARY > 12000;
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:
REPHEADER OFF
Syntax
ACC[EPT] variable [NUM[BER] | CHAR | DATE | BINARY_FLOAT | BINARY_DOUBLE] [FOR[MAT] format] [DEF[AULT] default] [PROMPT text|NOPR[OMPT]] [HIDE]
Reads a line of input and stores it in a given substitution variable.
Terms
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 variable a NUMBER datatype. If the reply does not match the datatype, ACCEPT gives an error message and prompts again.
CHAR
Makes the variable a CHAR datatype. The maximum CHAR length 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.
BINARY_FLOAT
Makes the variable a BINARY_FLOAT datatype. BINARY_FLOAT is a floating-point number that conforms substantially with the Institute for Electrical and Electronics Engineers (IEEE) Standard for Binary Floating-Point Arithmetic, IEEE Standard 754-1985.
BINARY_DOUBLE
Makes the variable a BINARY_DOUBLE datatype. BINARY_DOUBLE is a floating-point number that conforms substantially with the Institute for Electrical and Electronics Engineers (IEEE) Standard for Binary Floating-Point Arithmetic, IEEE Standard 754-1985.
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. If an attempt is made to enter more characters than are specified by the char format, an error message is given and the value must be reentered. If an attempt is made to enter a greater number precision than is specified by the number format, an error message is given and the value must be reentered. The format element must be a text constant such as A10 or 9.999. See COLUMN FORMAT for a complete list of format elements.
Oracle Database date formats such as "dd/mm/yy" are valid when the datatype is DATE. DATE without a specified format defaults to the NLS_DATE_FORMAT of the current session. See the Oracle Database Administrator's Guide and the Oracle Database SQL Language Reference for information on Oracle Database 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 for more information.
Examples
To display the prompt "Password: ", place the reply in a CHAR variable named PSWD, and suppress the display, enter
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
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, HIRED, with the format "dd/mm/yyyy" and a default of "01/01/2003", enter
ACCEPT hired DATE FORMAT 'dd/mm/yyyy' DEFAULT '01/01/2003'- PROMPT 'Enter date hired: '
To display the prompt "Enter employee lastname: " and place the reply in a CHAR variable named LASTNAME, enter
ACCEPT lastname CHAR FORMAT 'A20' - PROMPT 'Enter employee lastname: '
Syntax
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
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 SET BUF[FER] {buffer|SQL} (obsolete) for more information about the obsolete form of this command.
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]
SQL
Clears the text from SQL buffer. CLEAR SQL has the same effect as CLEAR BUFFER, unless you are using multiple buffers.
See SET BUF[FER] {buffer|SQL} (obsolete) for more information about the obsolete form of this command.
TIMI[NG]
Deletes all timers created by the TIMING command.
Examples
To clear breaks, enter
CLEAR BREAKS
To clear column definitions, enter
CLEAR COLUMNS
Syntax
@@{url | file_name[.ext] } [arg...]
Runs a script. This command is almost identical to the @ (at sign) command. When running nested scripts it looks for nested scripts in the same path or url as the calling script. The @@ command functions similarly to @ and START.
Terms
url
Specifies the Uniform Resource Locator of a script to run on the specified web server. SQL*Plus supports HTTP and FTP protocols, but not HTTPS. HTTP authentication in the form http://username:password@machine_name.domain... is not supported in this release.
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 SET SUF[FIX] {SQL | text}.
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 the file, it searches a system-dependent path to find the file. Some operating systems may not support the path search. See the platform-specific Oracle documentation 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 given by 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, see Using Substitution Variables.
Usage
All previous settings like COLUMN command settings stay in effect when the script starts. If the script changes any setting, the 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).
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 SET SQLT[ERMINATOR] {; | c | ON | OFF} for more information.
Examples
Suppose that you have the following script named PRINTRPT:
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 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.
This chapter explains how to format your query results to produce a finished report. This chapter does not discuss HTML output, but covers the following topics:
Read this chapter while sitting at your computer and try out the examples shown. Before beginning, make sure you have access to the HR sample schema described in SQL*Plus Quick Start.
Through the SQL*Plus COLUMN command, you can change the column headings and reformat the column data in your query results.
When displaying column headings, you can either use the default heading or you can change it using the COLUMN command. The following sections describe how default headings are derived and how to alter them using the COLUMN command. See the COLUMN command for more details.
SQL*Plus uses column or expression names as default column headings when displaying query results. Column names are often short and cryptic, however, and expressions can be hard to understand.
You can define a more useful column heading with the HEADING clause of the COLUMN command, in the following format:
COLUMN column_name HEADING column_heading
Example 6-1 Changing a Column Heading
To produce a report from EMP_DETAILS_VIEW with new headings specified for LAST_NAME, SALARY, and COMMISSION_PCT, enter the following commands:
COLUMN LAST_NAME HEADING 'LAST NAME' COLUMN SALARY HEADING 'MONTHLY SALARY' COLUMN COMMISSION_PCT HEADING COMMISSION SELECT LAST_NAME, SALARY, COMMISSION_PCT FROM EMP_DETAILS_VIEW WHERE JOB_ID='SA_MAN';
LAST NAME MONTHLY SALARY COMMISSION ------------------------- -------------- ---------- Russell 14000 .4 Partners 13500 .3 Errazuriz 12000 .3 Cambrault 11000 .3 Zlotkey 10500 .2 |
Note: The new headings will remain in effect until you enter different headings, reset each column's format, or exit from SQL*Plus. |
To change a column heading to two or more words, enclose the new heading in single or double quotation marks when you enter the COLUMN command. To display a column heading on more than one line, use a vertical bar (|) where you want to begin a new line. (You can use a character other than a vertical bar by changing the setting of the HEADSEP variable of the SET command. See the SET command for more information.)
Example 6-2 Splitting a Column Heading
To give the columns SALARY and LAST_NAME the headings MONTHLY SALARY and LAST NAME respectively, and to split the new headings onto two lines, enter
COLUMN SALARY HEADING 'MONTHLY|SALARY' COLUMN LAST_NAME HEADING 'LAST|NAME'
Now rerun the query with the slash (/) command:
/
LAST MONTHLY NAME SALARY COMMISSION ------------------------- ---------- ---------- Russell 14000 .4 Partners 13500 .3 Errazuriz 12000 .3 Cambrault 11000 .3 Zlotkey 10500 .2 |
Example 6-3 Setting the Underline Character
To change the character used to underline headings to an equal sign and rerun the query, enter the following commands:
SET UNDERLINE = /
LAST MONTHLY NAME SALARY COMMISSION ========================= ========== ========== Russell 14000 .4 Partners 13500 .3 Errazuriz 12000 .3 Cambrault 11000 .3 Zlotkey 10500 .2 |
Now change the underline character back to a dash:
SET UNDERLINE '-'
Note: You must enclose the dash in quotation marks; otherwise, SQL*Plus interprets the dash as a hyphen indicating that you wish to continue the command on another line. |
When displaying NUMBER columns, you can either accept the SQL*Plus default display width or you can change it using the COLUMN command. Later sections describe the default display and how you can alter it with the COLUMN command. The format model will stay in effect until you enter a new one, reset the column's format with
COLUMN column_name CLEAR
or exit from SQL*Plus.
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 normally displays numbers with as many digits as are required for accuracy, up to a standard display width determined by the value of the NUMWIDTH variable of the SET command (normally 10). If a number is larger than the value of SET NUMWIDTH, SQL*Plus rounds the number up or down to the maximum number of characters allowed if possible, or displays hashes if the number is too large.
You can choose a different format for any NUMBER column by using a format model in a COLUMN command. A format model is a representation of the way you want the numbers in the column to appear, using 9s to represent digits.
The COLUMN command identifies the column you want to format and the model you want to use, as shown:
COLUMN column_name FORMAT model
Use format models to add commas, dollar signs, angle brackets (around negative values), and leading zeros to numbers in a given column. You can also round the values to a given number of decimal places, display minus signs to the right of negative values (instead of to the left), and display values in exponential notation.
To use more than one format model for a single column, combine the desired models in one COLUMN command (see Example 6-4). See COLUMN for a complete list of format models and further details.
Example 6-4 Formatting a NUMBER Column
To display SALARY with a dollar sign, a comma, and the numeral zero instead of a blank for any zero values, enter the following command:
COLUMN SALARY FORMAT $99,990
Now rerun the current query:
/
LAST MONTHLY NAME SALARY COMMISSION ------------------------- -------- ---------- Russell $14,000 .4 Partners $13,500 .3 Errazuriz $12,000 .3 Cambrault $11,000 .3 Zlotkey $10,500 .2 |
Use a zero in your format model, as shown, when you use other formats such as a dollar sign and wish to display a zero in place of a blank for zero values.
When displaying datatypes, you can either accept the SQL*Plus default display width or you can change it using the COLUMN command. The format model will stay in effect until you enter a new one, reset the column's format with
COLUMN column_name CLEAR
or exit from SQL*Plus. Datatypes, in this manual, include the following types:
The default width of datatype columns is the width of the column in the database. The column width of a LONG, BLOB, BFILE, CLOB, NCLOB or XMLType defaults to the value of SET LONGCHUNKSIZE or SET LONG, whichever is the smaller.
The default width and format of unformatted DATE columns in SQL*Plus is determined by the database NLS_DATE_FORMAT parameter. Otherwise, the default format width is A9. See the FORMAT clause of the COLUMN command for more information on formatting DATE columns.
Left justification is the default for datatypes.
You can change the displayed width of a datatype or DATE, by using the COLUMN command with a format model consisting of the letter A (for alphanumeric) followed by a number representing the width of the column in characters.
Within the COLUMN command, identify the column you want to format and the model you want to use:
COLUMN column_name FORMAT model
If you specify a width shorter than the column heading, SQL*Plus truncates the heading. See the COLUMN command for more details.
Example 6-5 Formatting a Character Column
To set the width of the column LAST_NAME to four characters and rerun the current query, enter
COLUMN LAST_NAME FORMAT A4 /
LAST MONTHLY NAME SALARY COMMISSION ---- -------- ---------- Russ $14,000 .4 ell Part $13,500 .3 ners Erra $12,000 .3 zuri z LAST MONTHLY NAME SALARY COMMISSION ---- -------- ---------- Camb $11,000 .3 raul t Zlot $10,500 .2 key |
If the WRAP variable of the SET command is set to ON (its default value), the employee names wrap to the next line after the fourth character, as shown in Example 6-5, "Formatting a Character Column". If WRAP is set to OFF, the names are truncated (cut off) after the fourth character.
The system variable WRAP controls all columns; you can override the setting of WRAP for a given column through the WRAPPED, WORD_WRAPPED, and TRUNCATED clauses of the COLUMN command. See the COLUMN command for more information on these clauses. You will use the WORD_WRAPPED clause of COLUMN later in this chapter.
NCLOB, BLOB, BFILE or multibyte CLOB columns cannot be formatted with the WORD_WRAPPED option. If you format an NCLOB, BLOB, BFILE or multibyte CLOB column with COLUMN WORD_WRAPPED, the column data behaves as though COLUMN WRAPPED was applied instead.
Note: The column heading is truncated regardless of the setting of WRAP or any COLUMN command clauses. |
Now return the column to its previous format:
COLUMN LAST_NAME FORMAT A10
Example 6-6 Formatting an XMLType Column
Before illustrating how to format an XMLType column, you must create a table with an XMLType column definition, and insert some data into the table. You can create an XMLType column like any other user-defined column. To create a table containing an XMLType column, enter
CREATE TABLE warehouses ( warehouse_id NUMBER(3), warehouse_spec SYS.XMLTYPE, warehouse_name VARCHAR2 (35), location_id NUMBER(4));
To insert a new record containing warehouse_id and warehouse_spec values into the new warehouses table, enter
INSERT into warehouses (warehouse_id, warehouse_spec) VALUES (100, sys.XMLTYPE.createXML( '<Warehouse whNo="100"> <Building>Owned</Building> </Warehouse>'));
To set the XMLType column width to 20 characters and then select the XMLType column, enter
COLUMN Building FORMAT A20 SELECT w.warehouse_spec.extract('/Warehouse/Building/text()').getStringVal() "Building" FROM warehouses w;
Building -------------------- Owned |
For more information about the createXML, extract, text and getStringVal functions, and about creating and manipulating XMLType data, see Oracle Database PL/SQL Packages and Types Reference.
When you want to give more than one column the same display attributes, you can reduce the length of the commands you must enter by using the LIKE clause of the COLUMN command. The LIKE clause tells SQL*Plus to copy the display attributes of a previously defined column to the new column, except for changes made by other clauses in the same command.
Example 6-7 Copying a Column's Display Attributes
To give the column COMMISSION_PCT the same display attributes you gave to SALARY, but to specify a different heading, enter the following command:
COLUMN COMMISSION_PCT LIKE SALARY HEADING BONUS
Rerun the query:
/
LAST MONTHLY NAME SALARY BONUS ---------- -------- -------- Russell $14,000 $0 Partners $13,500 $0 Errazuriz $12,000 $0 Cambrault $11,000 $0 Zlotkey $10,500 $0 |
To list the current display attributes for a given column, use the COLUMN command followed by the column name only, as shown:
COLUMN column_name
To list the current display attributes for all columns, enter the COLUMN command with no column names or clauses after it:
COLUMN
To reset the display attributes for a column to their default values, use the CLEAR clause of the COLUMN command as shown:
COLUMN column_name CLEAR
Example 6-8 Resetting Column Display Attributes to their Defaults
To reset all column display attributes to their default values, enter:
CLEAR COLUMNS
columns cleared |
You can suppress and restore the display attributes you have given a specific column. To suppress a column's display attributes, enter a COLUMN command in the following form:
COLUMN column_name OFF
OFF tells SQL*Plus to use the default display attributes for the column, but does not remove the attributes you have defined through the COLUMN command. To restore the attributes you defined through COLUMN, use the ON clause:
COLUMN column_name ON
As you have seen, by default SQL*Plus wraps column values to additional lines when the value does not fit the column width. If you want to insert a record separator (a line of characters or a blank line) after each wrapped line of output (or after every row), use the RECSEP and RECSEPCHAR variables of the SET command.
RECSEP determines when the line of characters is printed; you set RECSEP to EACH to print after every line, to WRAPPED to print after wrapped lines, and to OFF to suppress printing. The default setting of RECSEP is WRAPPED.
RECSEPCHAR sets the character printed in each line. You can set RECSEPCHAR to any character.
You may wish to wrap whole words to additional lines when a column value wraps to additional lines. To do so, use the WORD_WRAPPED clause of the COLUMN command as shown:
COLUMN column_name WORD_WRAPPED
Example 6-9 Printing a Line of Characters after Wrapped Column Values
To print a line of dashes after each wrapped column value, enter the commands:
SET RECSEP WRAPPED SET RECSEPCHAR "-"
Finally, enter the following query:
SELECT LAST_NAME, JOB_TITLE, CITY FROM EMP_DETAILS_VIEW WHERE SALARY>12000;
Now restrict the width of the column JOB_TITLE and tell SQL*Plus to wrap whole words to additional lines when necessary:
COLUMN JOB_TITLE FORMAT A20 WORD_WRAPPED
Run the query:
/
LAST_NAME JOB_TITLE CITY ------------------------- -------------------- -------- King President Seattle Kochhar Administration Vice Seattle President ------------------------------------------------------- De Haan Administration Vice Seattle President ------------------------------------------------------- Russell Sales Manager Oxford Partners Sales Manager Oxford Hartstein Marketing Manager Toronto 6 rows selected. |
If you set RECSEP to EACH, SQL*Plus prints a line of characters after every row (after every department, for the above example).
Before continuing, set RECSEP to OFF to suppress the printing of record separators:
SET RECSEP OFF
When you use an ORDER BY clause in your SQL SELECT command, rows with the same value in the ordered column (or expression) are displayed together in your output. You can make this output more useful to the user by using the SQL*Plus BREAK and COMPUTE commands to create subsets of records and add space or summary lines after each subset.
The column you specify in a BREAK command is called a break column. By including the break column in your ORDER BY clause, you create meaningful subsets of records in your output. You can then add formatting to the subsets within the same BREAK command, and add a summary line (containing totals, averages, and so on) by specifying the break column in a COMPUTE command.
SELECT DEPARTMENT_ID, LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE SALARY > 12000 ORDER BY DEPARTMENT_ID;
DEPARTMENT_ID LAST_NAME SALARY ------------- ------------------------- ---------- 20 Hartstein 13000 80 Russell 14000 80 Partners 13500 90 King 24000 90 Kochhar 17000 90 De Haan 17000 6 rows selected. |
To make this report more useful, you would use BREAK to establish DEPARTMENT_ID as the break column. Through BREAK you could suppress duplicate values in DEPARTMENT_ID and place blank lines or begin a new page between departments. You could use BREAK in conjunction with COMPUTE to calculate and print summary lines containing the total salary for each department and for all departments. You could also print summary lines containing the average, maximum, minimum, standard deviation, variance, or row count.
The BREAK command suppresses duplicate values by default in the column or expression you name. Thus, to suppress the duplicate values in a column specified in an ORDER BY clause, use the BREAK command in its simplest form:
BREAK ON break_column
Example 6-10 Suppressing Duplicate Values in a Break Column
To suppress the display of duplicate department numbers in the query results shown, enter the following commands:
BREAK ON DEPARTMENT_ID;
For the following query (which is the current query stored in the buffer):
SELECT DEPARTMENT_ID, LAST_NAME, SALARY FROM EMP_DETAILS_VIEW WHERE SALARY > 12000 ORDER BY DEPARTMENT_ID;