Sqlplus Users Guide and Reference
Sqlplus Users Guide and Reference
Sqlplus Users Guide and Reference
Release 2 (12.2)
E85819-01
May 2017
SQL*Plus User's Guide and Reference, Release 2 (12.2)
E85819-01
Copyright © 1996, 2017, Oracle and/or its affiliates. All rights reserved.
This software and related documentation are provided under a license agreement containing restrictions on
use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your
license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify,
license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means.
Reverse engineering, disassembly, or decompilation of this software, unless required by law for
interoperability, is prohibited.
The information contained herein is subject to change without notice and is not warranted to be error-free. If
you find any errors, please report them to us in writing.
If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on
behalf of the U.S. Government, then the following notice is applicable:
U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software,
any programs installed on the hardware, and/or documentation, delivered to U.S. Government end users are
"commercial computer software" pursuant to the applicable Federal Acquisition Regulation and agency-
specific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the
programs, including any operating system, integrated software, any programs installed on the hardware,
and/or documentation, shall be subject to license terms and license restrictions applicable to the programs.
No other rights are granted to the U.S. Government.
This software or hardware is developed for general use in a variety of information management applications.
It is not developed or intended for use in any inherently dangerous applications, including applications that
may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you
shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its
safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this
software or hardware in dangerous applications.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of
their respective owners.
Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are
used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Opteron,
the AMD logo, and the AMD Opteron logo are trademarks or registered trademarks of Advanced Micro
Devices. UNIX is a registered trademark of The Open Group.
This software or hardware and documentation may provide access to or information about content, products,
and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly
disclaim all warranties of any kind with respect to third-party content, products, and services unless otherwise
set forth in an applicable agreement between you and Oracle. Oracle Corporation and its affiliates will not be
responsible for any loss, costs, or damages incurred due to your access to or use of third-party content,
products, or services, except as set forth in an applicable agreement between you and Oracle.
Contents
Preface
Audience xv
Documentation Accessibility xv
Related Documents xv
Conventions xvi
2 Configuring SQL*Plus
2.1 SQL*Plus Environment Variables 2-1
iii
2.1.1 SQLPATH Registry Entry 2-3
2.2 SQL*Plus Configuration 2-3
2.2.1 Site Profile 2-4
2.2.1.1 Default Site Profile Script 2-5
2.2.2 User Profile 2-5
2.2.2.1 Modifying Your LOGIN File 2-5
2.2.3 Storing and Restoring SQL*Plus System Variables 2-6
2.2.3.1 Restoring the System Variables 2-6
2.2.4 About Installing Command-line Help 2-7
2.2.4.1 Running the hlpbld.sql Script to Install Command-line Help 2-7
2.2.4.2 Running the helpdrop.sql Script to Remove Command-line Help 2-7
2.2.5 About Configuring Oracle Net Services 2-8
3 Starting SQL*Plus
3.1 Login Username and Password 3-1
3.1.1 Secure External Password Store 3-2
3.1.2 Expired Password 3-2
3.1.3 About Changing your Password 3-2
3.2 About Connecting to a Database 3-2
3.2.1 Net Service Name 3-3
3.2.2 Full Connection Identifier 3-3
3.2.3 Easy Connection Identifier 3-4
3.2.4 Connectionless Session with /NOLOG 3-4
3.3 About Starting SQL*Plus 3-5
3.3.1 About Starting Command-line SQL*Plus 3-5
3.3.2 About Getting Command-line Help 3-6
3.4 About Exiting SQL*Plus Command-line 3-6
3.5 SQL*Plus Program Syntax 3-6
3.5.1 Options 3-7
3.5.1.1 HELP Option 3-7
3.5.1.2 VERSION Option 3-7
3.5.1.3 COMPATIBILITY Option 3-8
3.5.1.4 LOGON Option 3-8
3.5.1.5 FAST Option 3-8
3.5.1.6 MARKUP Options 3-8
3.5.1.7 MARKUP Usage Notes 3-11
3.5.1.8 No Login Time Option 3-12
3.5.1.9 RESTRICT Option 3-12
3.5.1.10 SILENT Option 3-13
3.5.1.11 AC Option 3-13
iv
3.5.2 Logon 3-13
3.5.3 Start 3-14
4 SQL*Plus Basics
4.1 About Entering and Executing Commands 4-1
4.1.1 The SQL Buffer 4-2
4.1.2 About Executing Commands 4-2
4.2 About Listing a Table Definition 4-2
4.3 About Listing PL/SQL Definitions 4-3
4.4 Running SQL Commands 4-3
4.4.1 About Understanding SQL Command Syntax 4-4
4.4.1.1 About Dividing a SQL Command into Separate Lines 4-4
4.4.1.2 About Ending a SQL Command 4-4
4.5 About Running PL/SQL Blocks 4-5
4.5.1 About Creating Stored Procedures 4-6
4.6 Running SQL*Plus Commands 4-7
4.6.1 About Understanding SQL*Plus Command Syntax 4-7
4.6.1.1 About Continuing a Long SQL*Plus Command on Additional Lines
4-7
4.7 System Variables that Affect How Commands Run 4-8
4.8 About Stopping a Command while it is Running 4-8
4.9 About Running Operating System Commands 4-9
4.10 About Pausing the Display 4-9
4.11 About Saving Changes to the Database Automatically 4-9
4.12 About Interpreting Error Messages 4-11
v
5.3.2 Using /*...*/ 5-8
5.3.3 Using - - 5-8
5.3.4 Notes on Placing Comments 5-8
5.4 Running Scripts 5-10
5.4.1 Running a Script as You Start SQL*Plus 5-11
5.5 Nesting Scripts 5-11
5.6 About Exiting from a Script with a Return Code 5-11
5.7 Defining Substitution Variables 5-12
5.8 About Using Predefined Variables 5-12
5.9 Using Substitution Variables 5-12
5.9.1 Where and How to Use Substitution Variables 5-13
5.9.2 Avoiding Unnecessary Prompts for Values 5-14
5.9.3 Restrictions 5-16
5.9.4 System Variables 5-17
5.10 Passing Parameters through the START Command 5-17
5.11 About Communicating with the User 5-18
5.11.1 Receiving a Substitution Variable Value 5-19
5.11.2 Customizing Prompts for Substitution Variable 5-19
5.11.3 Sending a Message and Accepting Return as Input 5-21
5.11.4 Clearing the Screen 5-21
5.12 About Using Bind Variables 5-21
5.12.1 Creating Bind Variables 5-21
5.12.2 Referencing Bind Variables 5-21
5.12.3 Displaying Bind Variables 5-22
5.12.4 Executing an Input Bind 5-22
5.13 Using REFCURSOR Bind Variables 5-23
5.14 Fetching Iterative Results from a SELECT inside a PL/SQL Block 5-25
vi
6.1.5 Listing and Resetting Column Display Attributes 6-7
6.1.6 About Suppressing and Restoring Column Display Attributes 6-8
6.1.7 Printing a Line of Characters after Wrapped Column Values 6-8
6.2 About Clarifying Your Report with Spacing and Summary Lines 6-9
6.2.1 Suppressing Duplicate Values in Break Columns 6-10
6.2.2 Inserting Space when a Break Column's Value Changes 6-10
6.2.3 Inserting Space after Every Row 6-11
6.2.4 Using Multiple Spacing Techniques 6-11
6.2.5 Listing and Removing Break Definitions 6-12
6.2.6 Computing Summary Lines when a Break Column's Value Changes 6-12
6.2.7 Computing Summary Lines at the End of the Report 6-15
6.2.8 Computing Multiple Summary Values and Lines 6-16
6.2.9 Listing and Removing COMPUTE Definitions 6-17
6.3 About Defining Page and Report Titles and Dimensions 6-18
6.3.1 Setting the Top and Bottom Titles and Headers and Footers 6-18
6.3.1.1 Positioning Title Elements 6-19
6.3.1.2 Indenting a Title Element 6-20
6.3.1.3 Entering Long Titles 6-21
6.3.2 Displaying System-Maintained Values in Titles 6-21
6.3.3 Listing, Suppressing, and Restoring Page Title Definitions 6-22
6.3.4 Displaying Column Values in Titles 6-22
6.3.5 About Displaying the Current Date in Titles 6-24
6.3.6 Setting Page Dimensions 6-24
6.4 About Storing and Printing Query Results 6-26
6.4.1 Creating a Flat File 6-26
6.4.2 Sending Results to a File 6-26
6.4.3 Sending Results to a Printer 6-27
8 Tuning SQL*Plus
8.1 About Tracing Statements 8-1
8.1.1 Controlling the Autotrace Report 8-1
8.1.2 Execution Plan 8-2
vii
8.1.3 Statistics 8-3
8.2 About Collecting Timing Statistics 8-5
8.3 Tracing Parallel and Distributed Queries 8-5
8.4 Execution Plan Output in Earlier Databases 8-7
8.5 About SQL*Plus Script Tuning 8-8
8.5.1 COLUMN NOPRINT 8-8
8.5.2 SET APPINFO OFF 8-8
8.5.3 SET ARRAYSIZE 8-9
8.5.4 SET DEFINE OFF 8-9
8.5.5 SET FLUSH OFF 8-9
8.5.6 SET LINESIZE 8-9
8.5.7 SET LONGCHUNKSIZE 8-9
8.5.8 SET PAGESIZE 8-9
8.5.9 SET SERVEROUTPUT 8-9
8.5.10 SET SQLPROMPT 8-10
8.5.11 SET TAB 8-10
8.5.12 SET TERMOUT 8-10
8.5.13 SET TRIMOUT ON SET TRIMSPOOL ON 8-10
8.5.14 UNDEFINE 8-10
9 SQL*Plus Security
9.1 About the PRODUCT_USER_PROFILE Table 9-1
9.1.1 About Creating the PUP Table 9-1
9.1.2 PUP Table Structure 9-2
9.1.3 Description and Use of PUP Columns 9-2
9.1.4 PUP Table Administration 9-3
9.2 Disabling SQL*Plus, SQL, and PL/SQL Commands 9-3
9.3 About Creating and Controlling Roles 9-6
9.3.1 About Disabling SET ROLE 9-7
9.3.2 About Disabling User Roles 9-7
9.4 About Disabling Commands with SQLPLUS -RESTRICT 9-8
9.5 About Program Argument Security 9-8
viii
10.2.4 PDB Shutdown 10-3
10.3 Redo Log Files 10-3
10.3.1 ARCHIVELOG Mode 10-3
10.4 Database Recovery 10-4
ix
12.23 EXIT 12-47
12.24 GET 12-48
12.25 HELP 12-49
12.26 HISTORY 12-50
12.27 HOST 12-53
12.28 INPUT 12-54
12.29 LIST 12-55
12.30 PASSWORD 12-56
12.31 PAUSE 12-57
12.32 PRINT 12-57
12.33 PROMPT 12-58
12.34 RECOVER 12-59
12.35 REMARK 12-65
12.36 REPFOOTER 12-66
12.37 REPHEADER 12-67
12.38 RUN 12-69
12.39 SAVE 12-70
12.40 SET 12-71
12.41 SET System Variable Summary 12-72
12.41.1 SET APPI[NFO]{ON | OFF | text} 12-75
12.41.2 SET ARRAY[SIZE] {15 | n} 12-76
12.41.3 SET AUTO[COMMIT]{ON | OFF | IMM[EDIATE] | n} 12-76
12.41.4 SET AUTOP[RINT] {ON | OFF} 12-77
12.41.5 SET AUTORECOVERY [ON | OFF] 12-77
12.41.6 SET AUTOT[RACE] {ON | OFF | TRACE[ONLY]} [EXP[LAIN]]
[STAT[ISTICS]] 12-77
12.41.7 SET BLO[CKTERMINATOR] {. | c | ON | OFF} 12-78
12.41.8 SET CMDS[EP] {; | c | ON | OFF} 12-78
12.41.9 SET COLINVI[SIBLE] [ON | OFF] 12-79
12.41.10 SET COLSEP { | text} 12-80
12.41.11 SET CON[CAT] {. | c | ON | OFF} 12-80
12.41.12 SET COPYC[OMMIT] {0 | n} 12-80
12.41.13 SET COPYTYPECHECK {ON | OFF} 12-81
12.41.14 SET DEF[INE] {& | c | ON | OFF} 12-81
12.41.15 SET DESCRIBE [DEPTH {1 | n | ALL}] [LINENUM {ON | OFF}]
[INDENT {ON | OFF}] 12-81
12.41.16 SET ECHO {ON | OFF} 12-82
12.41.17 SET EDITF[ILE] file_name[.ext] 12-82
12.41.18 SET EMB[EDDED] {ON | OFF} 12-82
12.41.19 SET ERRORL[OGGING] {ON | OFF} [TABLE [schema.]tablename]
[TRUNCATE] [IDENTIFIER identifier] 12-82
12.41.20 SET ESC[APE] {\ | c | ON | OFF} 12-87
x
12.41.21 SET ESCCHAR {@ | ? | % | $ | OFF} 12-87
12.41.22 SET EXITC[OMMIT] {ON | OFF} 12-88
12.41.23 SET FEED[BACK] {6 | n | ON | OFF | ONLY} 12-88
12.41.24 SET FLAGGER {OFF | ENTRY | INTERMED[IATE] | FULL} 12-89
12.41.25 SET FLU[SH] {ON | OFF} 12-89
12.41.26 SET HEA[DING] {ON | OFF} 12-89
12.41.27 SET HEADS[EP] { | c | ON | OFF} 12-90
12.41.28 SET HIST[ORY] {ON | OFF | n} 12-90
12.41.29 SET INSTANCE [instance_path | LOCAL] 12-90
12.41.30 SET LIN[ESIZE] {80 | n} 12-91
12.41.31 SET LOBOF[FSET] {1 | n} 12-91
12.41.32 SET LOBPREFETCH {0 | n} 12-91
12.41.33 SET LOGSOURCE [pathname] 12-92
12.41.34 SET LONG {80 | n} 12-92
12.41.35 SET LONGC[HUNKSIZE] {80 | n} 12-93
12.41.36 SET MARK[UP] 12-93
12.41.37 SET NEWP[AGE] {1 | n | NONE} 12-97
12.41.38 SET NULL text 12-98
12.41.39 SET NUMF[ORMAT] format 12-98
12.41.40 SET NUM[WIDTH] {10 | n} 12-98
12.41.41 SET PAGES[IZE] {14 | n} 12-98
12.41.42 SET PAU[SE] {ON | OFF | text} 12-98
12.41.43 SET RECSEP {WR[APPED] | EA[CH] | OFF} 12-98
12.41.44 SET RECSEPCHAR { | c} 12-99
12.41.45 SET ROWPREFETCH {1 | n} 12-99
12.41.46 SET SECUREDCOL {OFF | ON} [UNAUTH[ORIZED] text]
[UNK[NOWN] text] 12-99
12.41.47 SET SERVEROUT[PUT] {ON | OFF} [SIZE {n | UNL[IMITED]}]
[FOR[MAT] {WRA[PPED] | WOR[D_WRAPPED] | TRU[NCATED]}] 12-100
12.41.48 SET SHIFT[INOUT] {VIS[IBLE] | INV[ISIBLE]} 12-102
12.41.49 SET SHOW[MODE] {ON | OFF} 12-103
12.41.50 SET SQLBL[ANKLINES] {ON | OFF} 12-103
12.41.51 SET SQLC[ASE] {MIX[ED] | LO[WER] | UP[PER]} 12-103
12.41.52 SET SQLCO[NTINUE] {> | text} 12-103
12.41.53 SET SQLN[UMBER] {ON | OFF} 12-104
12.41.54 SET SQLPLUSCOMPAT[IBILITY] {x.y[.z]} 12-104
12.41.54.1 SQL*Plus Compatibility Matrix 12-104
12.41.55 SET SQLPRE[FIX] {# | c} 12-105
12.41.56 SET SQLP[ROMPT] {SQL> | text} 12-105
12.41.57 SET SQLT[ERMINATOR] {; | c | ON | OFF} 12-106
12.41.58 SET STATEMENTC[ACHE] {0 | n} 12-106
12.41.59 SET SUF[FIX] {SQL | text} 12-107
xi
12.41.60 SET TAB {ON | OFF} 12-107
12.41.61 SET TERM[OUT] {ON | OFF} 12-107
12.41.62 SET TI[ME] {ON | OFF} 12-107
12.41.63 SET TIMI[NG] {ON | OFF} 12-107
12.41.64 SET TRIM[OUT] {ON | OFF} 12-108
12.41.65 SET TRIMS[POOL] {ON | OFF} 12-108
12.41.66 SET UND[ERLINE] {- | c | ON | OFF} 12-108
12.41.67 SET VER[IFY] {ON | OFF} 12-108
12.41.68 SET WRA[P] {ON | OFF} 12-108
12.41.69 SET XMLOPT[IMIZATIONCHECK] [ON|OFF] 12-109
12.41.70 SET XQUERY BASEURI {text} 12-109
12.41.71 SET XQUERY ORDERING {UNORDERED | ORDERED |
DEFAULT} 12-109
12.41.72 SET XQUERY NODE {BYVALUE | BYREFERENCE | DEFAULT} 12-110
12.41.73 SET XQUERY CONTEXT {text} 12-110
12.42 SHOW 12-111
12.43 SHUTDOWN 12-116
12.44 SPOOL 12-118
12.45 START 12-119
12.46 STARTUP 12-121
12.47 STORE 12-125
12.48 TIMING 12-126
12.49 TTITLE 12-127
12.50 UNDEFINE 12-129
12.51 VARIABLE 12-130
12.52 WHENEVER OSERROR 12-136
12.53 WHENEVER SQLERROR 12-137
12.54 XQUERY 12-139
A SQL*Plus Limits
xii
B SQL*Plus COPY Command
B.1 COPY Command Syntax B-1
B.1.1 Terms B-1
B.1.2 Usage B-3
B.1.3 Examples B-3
B.2 Copying Data from One Database to Another B-3
B.2.1 Understanding COPY Command Syntax B-4
B.2.2 About Controlling Treatment of the Destination Table B-5
B.2.3 About Interpreting the Messages that COPY Displays B-6
B.2.4 Specifying Another User's Table B-7
B.3 About Copying Data between Tables on One Database B-7
xiii
D.3.1 Installing SQL*Plus Instant Client on UNIX or Linux D-4
D.3.2 Installing SQL*Plus Instant Client on Windows D-4
D.4 About Configuring SQL*Plus Instant Client D-5
D.4.1 Configuring SQL*Plus Instant Client on Linux (from RPMs) D-5
D.4.2 Configuring SQL*Plus Instant Client on Linux (from Client Media or Zip
File) and UNIX D-5
D.4.3 Configuring SQL*Plus Instant Client on Windows D-6
D.5 About Connecting to a Database with SQL*Plus Instant Client D-6
D.6 AS SYSDBA or AS SYSOPER Connections with SQL*Plus Instant Client D-7
D.7 About Uninstalling Instant Client D-7
D.7.1 Uninstalling SQL*Plus Instant Client D-8
D.7.2 Uninstalling the Complete Instant Client D-8
Index
xiv
Preface
The SQL*Plus (pronounced "sequel plus") User's Guide and Reference introduces
SQL*Plus and its uses, and describes each SQL*Plus command.
This preface contains these topics:
• Audience
• Documentation Accessibility
• Related Documents
• Conventions
Audience
The SQL*Plus User's Guide and Reference is intended for business and technical
users and system administrators who perform the following tasks:
• Develop and run batch scripts
• Format, calculate on, store, print and create web output from query results
• Examine table and object definitions
• Perform database administration
This document assumes a basic understanding of the SQL language. If you do not
have familiarity with SQL, see the Oracle Database SQL Language Reference. If you
plan to use PL/SQL with SQL*Plus, see the Oracle Database PL/SQL Language
Reference.
Documentation Accessibility
For information about Oracle's commitment to accessibility, visit the Oracle
Accessibility Program website at http://www.oracle.com/pls/topic/lookup?
ctx=acc&id=docacc.
Related Documents
For more information, see these Oracle resources:
xv
Preface
Conventions
The following text conventions are used in this document:
Convention Meaning
boldface Boldface type indicates graphical user interface elements associated
with an action, or terms defined in text or the glossary.
italic Italic type indicates book titles, emphasis, or placeholder variables
for which you supply particular values.
monospace Monospace type indicates commands within a paragraph, URLs,
code in examples, text that appears on the screen, or text that you
enter.
xvi
Changes in This Release for SQL*Plus
This preface lists changes in the SQL*Plus User's Guide and Reference
New Features
The following features are new in this release:
• Support for command history
SQL*Plus now supports command history. The command history feature enables
users to run, edit, or delete previously used SQL*Plus, SQL, or PL/SQL
commands from the history list in the current session.
See HISTORY
See SET HIST[ORY] {ON | OFF | n}
See SHOW HISTORY
• Support for long identifiers
SQL*Plus now supports object lengths of 128 bytes. In previous releases, the
object length limit was 30 bytes.
• Commands to improve performance
SQL*Plus has new commands that improve performance in certain cases. The
new commands enable users to control row and LOB prefetching, as well as
statement caching.
See SET LOBPREFETCH {0 | n}
See SET ROWPREFETCH {1 | n}
See SET STATEMENTC[ACHE] {0 | n}
• New Administrative Privilege
The SQLPLUS and CONNECT commands now support the new user privilege
SYSRAC as well as the existing SYSBACKUP |SYSDG | SYSKM |SYSASM |
SYSDBA |SYSOPER privileges.
See SQLPLUS Program Syntax
See CONNECT
See Administrative User Accounts
xvii
Changes in This Release for SQL*Plus
• Support for input binding by using the VARIABLE command. The VARIABLE
command now supports input binding which can be used in SQL and PL/SQL
statements.
• Support for CSV format data. The SET MARKUP command now has a CSV option
to output data in CSV format.
• The SET FEEDBACK command has an ONLY option to display the number of
rows selected. No data is displayed.
• SQL*Plus command-line option –AC sets the Application Continuity flag for the
session. For more information about Application Continuity, see the Oracle Call
Interface Programmer's Guide.
• SQL*Plus command-line option –F[ast] changes the values of the following default
settings:
– ARRAYSIZE = 100
– LOBPREFETCH = 16384
– PAGESIZE = 50000
– ROWPREFETCH = 2
– STATEMENTCACHE = 20
These settings improve general performance.
Desupported Features
Some features previously described in this document are desupported in Oracle
Database 12c Release 2 (12.2). See Oracle Database Upgrade Guide for a list of
desupported features.
xviii
SQL*Plus Quick Start
These instructions are to enable you to login and connect to a database after you have
installed SQL*Plus. You can connect to the default database you created during
installation, or to another existing Oracle database.
• SQL*Plus Resources
• SQL*Plus Overview
• SQL*Plus Prerequisites
• Starting SQL*Plus Command-line
• About Starting SQL*Plus Instant Client
• About Connecting to a Different Database
• About Sample Schemas and SQL*Plus
• Running your first Query
• About Exiting SQL*Plus
SQL*Plus Resources
• SQL*Plus Discussion Forum at https://forums.oracle.com/forums/forum.jspa?
forumID=144.
SQL*Plus Overview
SQL*Plus is an interactive and batch query tool that is installed with every Oracle
Database installation. It has a command-line user interface.
There is also the SQL*Plus Instant Client which is a standalone command-line
interface available on platforms that support the OCI Instant Client. SQL*Plus Instant
Client connects to any available Oracle database, but does not require its own Oracle
database installation. See the Oracle Call Interface Programmer's Guide for more
information on the OCI Instant Client.
SQL*Plus has its own commands and environment, and it provides access to the
Oracle Database. It enables you to enter and execute SQL, PL/SQL, SQL*Plus and
operating system commands to perform the following:
• Format, perform calculations on, store, and print from query results
• Examine table and object definitions
• Develop and run batch scripts
• Perform database administration
xix
SQL*Plus Quick Start
You can use SQL*Plus to generate reports interactively, to generate reports as batch
processes, and to output the results to text file, to screen, or to HTML file for browsing
on the Internet. You can generate reports dynamically using the HTML output facility of
SQL*Plus.
Similarly, to list column definitions for the EMPLOYEES table, enter the command:
DESCRIBE EMPLOYEES
xx
SQL*Plus Quick Start
SQL*Plus Client
The command-line user interface is the character-based terminal implementation.
Oracle Database
Oracle Database Net components provide communication between the SQL*Plus
Client and Oracle Database.
SQL*Plus Prerequisites
SQL*Plus is a component of Oracle Database. SQL*Plus is installed by default when
you install the Oracle Database.
Some aspects of Oracle Database and SQL*Plus differ from one computer and
operating system to another. These topics are discussed in the Oracle Database
Installation Guide for each operating system that SQL*Plus supports.
What is necessary before you can run SQL*Plus?
• Install Oracle Database or Oracle Client. See the Oracle Database Installation
Guide for your operating system available at http://www.oracle.com/technetwork/.
• Obtain an Oracle Database login username and password during installation or
from your Database Administrator. See Login Username and Password.
• Ensure a sample database is installed and that you have a login username and
password for it during Oracle Database installation. See About Sample Schemas
and SQL*Plus.
• Create a default database during installation or obtain the connection identifier for
the Oracle Database you want to connect to from your Database Administrator.
See About Connecting to a Database.
• Ensure the database you want to connect to is started. See the STARTUP
command.
xxi
SQL*Plus Quick Start
sqlplus hr@\"//mymachine.mydomain:port/MYDB\"
Net Service Names can be stored in several places, including Oracle Names. See the
Net Services Reference Guide for more information.
If you want to use Net Service Names configured in a local Oracle Net tnsnames.ora
file, then set the environment variable TNS_ADMIN to the directory containing the
tnsnames.ora file. For example, on UNIX, if your tnsnames.ora file is in /home/user1
and it defines the Net Service Name MYDB2:
TNS_ADMIN=/home/user1
export TNS_ADMIN
sqlplus hr@MYDB2
The TWO_TASK (on UNIX) or LOCAL (on Windows) environment variable can be set
to a connection identifier. This removes the need to explicitly enter the connection
identifier whenever a connection is made in SQL*Plus or SQL*Plus Instant Client. This
UNIX example connects to the database known as MYDB4:
TNS_ADMIN=/home/user1
export TNS_ADMIN
TWO_TASK=MYDB4
export TWO_TASK
sqlplus hr
xxii
SQL*Plus Quick Start
For more information about the sample schemas, see the Oracle Database Sample
Schemas guide.
For further information about unlocking the HR account, see the Oracle Database
Sample Schemas guide. The HR user is primarily to enable you to access the HR
sample schema and is necessary to enable you to run the examples in this guide.
Each table in the database is "owned" by a particular user. You may want to have your
own copies of the sample tables to use as you try the examples in this guide. To get
xxiii
SQL*Plus Quick Start
your own copies of the HR tables, see your DBA or see the Oracle Database Sample
Schemas guide, or you can create the HR tables with the script HR_MAIN.SQL which
is located in the following directory on UNIX:
$ORACLE_HOME/demo/schema/human_resources/hr_main.sql
To rename the column headings, and to select data from the HR sample schema view,
EMP_DETAILS_VIEW, enter
COLUMN FIRST_NAME HEADING "First Name"
COLUMN LAST_NAME HEADING "Family Name"
SELECT FIRST_NAME, LAST_NAME
xxiv
SQL*Plus Quick Start
FROM EMP_DETAILS_VIEW
WHERE LAST_NAME LIKE 'K%';
xxv
Part I
SQL*Plus Getting Started
Part 1 provides the information you need to get started with SQL*Plus. It describes the
command-line user interface, provides configuration information and information you
need to log in and run SQL*Plus.
Part 1 contains the following chapters:
• SQL*Plus User Interface
• Configuring SQL*Plus
• Starting SQL*Plus
1
SQL*Plus User Interface
This chapter describes the SQL*Plus command-line user interface. It contains the
following topics:
• About The Command-line Screen
• Changing the Command-line Font and Font Size
When SQL*Plus starts, it displays the date and time, the SQL*Plus version and
copyright information before the SQL*Plus prompt appears. The default prompt for
SQL*Plus command-line is:
SQL>
1-1
Chapter 1
Changing the Command-line Font and Font Size
4. Select the font size to use from the Size box. Raster font sizes are shown as width
by height in pixels. TrueType font sizes are shown as height in pixels.
5. Select the font to use from the Font box.
6. Select the Bold Fonts check box to use a bold version of the font.
For more information about changing Command Prompt properties, see Windows Help
or click Help in the Command Prompt Properties dialog.
1-2
2
Configuring SQL*Plus
This chapter explains how to configure your SQL*Plus command-line environment. It
has the following topics:
• SQL*Plus Environment Variables
• SQL*Plus Configuration
2-1
Chapter 2
SQL*Plus Environment Variables
2-2
Chapter 2
SQL*Plus Configuration
See the Registry Editor's help system for instructions on how to edit the SQLPATH
registry entry.
2-3
Chapter 2
SQL*Plus Configuration
Note:
The Site Profile and User Profile files are run after a successful Oracle
Database connection from a SQLPLUS or CONNECT command, or where /NOLOG is
specified.The Site Profile and User Profile files are not run when you switch to
another PDB using ALTER SESSION SET CONTAINER.
2-4
Chapter 2
SQL*Plus Configuration
The Site Profile script is generally named glogin.sql. SQL*Plus executes this script
whenever a user starts a SQL*Plus session and successfully establishes the Oracle
Database connection.
The Site Profile enables the DBA to set up site wide SQL*Plus environment defaults
for all users of a particular SQL*Plus installation
Users cannot directly access the Site Profile.
Note:
SQL*Plus will no longer search for login.sql in the current directory.
You can add any SQL commands, PL/SQL blocks, or SQL*Plus commands to your
user profile. When you start SQL*Plus, it automatically searches for your user profile
and runs the commands it contains.
2-5
Chapter 2
SQL*Plus Configuration
See Also:
• SET command for more information on these and other SET command
variables you may wish to set in your SQL*Plus LOGIN file.
• About Using Predefined Variables for more information about predefined
variables.
Enter a file name and file extension, or enter only the file name to use the default
extension .SQL. You can use the SET SUF[FIX] {SQL | text} command to change the
default file extension.
If the file has the default extension (as specified by the SET SUF[FIX] {SQL | text}
command), you do not need to add the period and extension to the file name.
You can also use the @ (at sign) or the @@ (double at sign) commands to run the
script.
Created file plusenv
PAGESIZE 24
SET PAGESIZE 60
SHOW PAGESIZE
PAGESIZE 60
The original values of system variables can then be restored from the script:
2-6
Chapter 2
SQL*Plus Configuration
START plusenv
SHOW PAGESIZE
PAGESIZE 24
You are prompted to enter the password you have defined for the SYSTEM user.
2. In UNIX run the SQL script, HLPBLD.SQL, from SQL*Plus with:
@$ORACLE_HOME/SQLPLUS/ADMIN/HELP/HLPBLD.SQL HELPUS.SQL
2-7
Chapter 2
SQL*Plus Configuration
SQLPLUS SYSTEM
You are prompted to enter the password you have defined for the SYSTEM user.
2. In UNIX run the SQL script, HELPDROP.SQL, from SQL*Plus with:
@$ORACLE_HOME/SQLPLUS/ADMIN/HELP/HELPDROP.SQL
The HELPDROP.SQL script drops the help tables, and then disconnects.
2-8
3
Starting SQL*Plus
This chapter describes how to start, login, and connect to a database, how to get help,
and how to exit SQL*Plus.
Specific topics discussed are:
• Login Username and Password
• About Connecting to a Database
• About Starting SQL*Plus
• About Exiting SQL*Plus Command-line
• SQLPLUS Program Syntax
3-1
Chapter 3
About Connecting to a Database
Note that you need not specify database login credentials in this CONNECT statement.
Instead your system looks for database login credentials in the client wallet.
See Also:
Oracle Database Administrator's Guide for information about configuring your
client to use secure external password store and for information about
managing credentials in it.
3-2
Chapter 3
About Connecting to a Database
You must enter either a connection identifier or a net service name to connect to a
database other than the default.
The connection identifier or net service name is entered:
• as an argument to the SQLPLUS Program Syntax when starting a command-line
session.
• as an argument to the CONNECT command from a current session. For detailed
usage, see Accessing a Container in a CDB in the Oracle Database
Administrator's Guide.
To use a net service name (alias), it must have an entry in the tnsnames.ora file on the
machine running SQL*Plus. An entry in tnsnames.ora is not required if you use a
connection identifier.
Example 3-1 The tnsnames.ora entry for the sales database
SALES1 =
(DESCRIPTION =
(ADDRESS=(PROTOCOL=tcp)(HOST=sales-server)(PORT=1521) )
(CONNECT_DATA=
(SERVICE_NAME=sales.us.acme.com) ) )
Example 3-2 Start a command-line session to the sales database using the net
service name
SQLPLUS hr@SALES1
The SERVICE_NAME is the global database name entered during database creation. It
combines a database name with a domain name. For example, the SERVICE_NAME
sales.us.acme.com has a database name of sales and a domain of us.acme.com.
3-3
Chapter 3
About Connecting to a Database
An INSTANCE_NAME is the name you give to the database instance during creation. It
defaults to the SID you entered during database creation.
An Oracle System Identifier (SID) identifies a specific Oracle release 8.0 database
instance.
You can optionally use an INSTANCE_NAME in place of the SERVICE_NAME phrase.
Use a SID in place of the SERVICE_NAME when connecting to an Oracle release 8.0 or
earlier database.
Example 3-3 Full connection identifier for SALES1
SQLPLUS hr@\"(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=sales-server)(PORT=1521) )
(CONNECT_DATA=
(SERVICE_NAME=sales.us.acme.com) ) )\"
Example 3-4 Start a command-line session to the sales database using the
easy connection identifier
sqlplus hr@\"sales-server:1521/sales.us.acme.com\"
Example 3-5 CONNECT to the sales database using the easy connection
identifier
When the password is omitted, the connect string needs to be quoted.
connect hr@"sales-server:1521/sales.us.acme.com"
The easy connection identifier can be used wherever you can use a full connection
identifier, or a net service name. The easy syntax is less complex, and no
tnsnames.ora entry is required.
3-4
Chapter 3
About Starting SQL*Plus
Note:
Some operating systems expect you to enter commands in lowercase letters.
If your system expects lowercase, enter the SQLPLUS command in
lowercase.
SQLPLUS
SQL*Plus displays its version number, the current date, and copyright information,
and prompts you for your username (the text displayed on your system may differ
slightly):
SQL*Plus: Release 12.2.0.1.0 Production on Wed Jul 6 18:33:32 2016
3-5
Chapter 3
About Exiting SQL*Plus Command-line
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
The SQL*Plus command prompt indicates that SQL*Plus is ready to accept your
commands.
If SQL*Plus does not start, you should see a message to help you correct the problem.
Example 3-7 Starting SQL*Plus
This example shows you how to start SQL*Plus:
3-6
Chapter 3
SQL*Plus Program Syntax
• html_option
csv_option has the following syntax:
CSV {ON|OFF} [DELIMI[TER] character] [QUOTE {ON|OFF}]
WARNING:
Including your password in plain text is a security risk. You can avoid this risk
by omitting the password, and entering it only when the system prompts for it.
You have the option of entering logon. If you do not specify logon but do specify start,
SQL*Plus assumes that the first line of the script contains a valid logon. If neither start
nor logon are specified, SQL*Plus prompts for logon information.
3.5.1 Options
The following sections contain descriptions of SQLPLUS command options:
Displays the usage and syntax for the SQLPLUS command, and then returns control
to the operating system.
Displays the current version and level number for SQL*Plus, and then returns control
to the operating system.
3-7
Chapter 3
SQL*Plus Program Syntax
Specifies not to reprompt for username or password if the initial connection does not
succeed. This can be useful in operating system scripts that must either succeed or
fail and you don't want to be reprompted for connection details if the database server
is not running.
The FAST option improves general performance. This command line option changes
the values of the following default settings:
• ARRAYSIZE = 100
• LOBPREFETCH = 16384
• PAGESIZE = 50000
• ROWPREFETCH = 2
• STATEMENTCACHE = 20
You can use the MARKUP options to generate output in HTML or CSV (Character
Separated Values) format, through a query or script.
MARKUP currently supports HTML 4.0 transitional, and the CSV format.
Use SQLPLUS -MARKUP to produce output in HTML or CSV format.
Note:
Depending on your operating system, the complete markup_option clause for
the SQL*PLUS command may need to be contained in quotes.
For HTML output, use SQLPLUS -MARKUP HTML ON or SQLPLUS -MARKUP HTML
ON SPOOL ON to produce standalone web pages. SQL*Plus will generate complete
3-8
Chapter 3
SQL*Plus Program Syntax
HTML pages automatically encapsulated with <HTML> and <BODY> tags. The HTML
tags in a spool file are closed when SPOOL OFF is executed or SQL*Plus exits.
The -SILENT and -RESTRICT command-line options may be useful when used in
conjunction with -MARKUP.
You can use MARKUP HTML ON to produce HTML output in either the <PRE> tag or
in an HTML table. Output to a table uses standard HTML <TABLE>, <TR> and <TD>
tags to automatically encode the rows and columns resulting from a query. Output to
an HTML table is the default behavior when the HTML option is set ON. You can
generate output using HTML <PRE> tags by setting PREFORMAT ON.
For CSV output, use SQLPLUS -MARKUP CSV ON to produce output in CSV format.
You can specify the delimiter character by using the DELIMITER option. You can also
output text without quotes by using QUOTE OFF.
Use the SHOW MARKUP command to view the status of MARKUP options.
The SQLPLUS -MARKUP command has the same functionality as the SET MARKUP
command. These options are described in this section. For other information on the
SET MARKUP command, see the SET command.
CSV {ON|OFF}
CSV is a mandatory MARKUP argument which specifies that the type of output to be
generated is CSV. The optional CSV arguments, ON and OFF, specify whether or not
to generate CSV output. The default is OFF. You can turn CSV output ON and OFF as
required during a session.
HTML {ON|OFF}
HTML is a mandatory MARKUP argument which specifies that the type of output to be
generated is HTML. The optional HTML arguments, ON and OFF, specify whether or
not to generate HTML output. The default is OFF.
MARKUP HTML ON generates HTML output using the specified MARKUP options.
You can turn HTML output ON and OFF as required during a session.
HEAD text
The HEAD text option enables you to specify content for the <HEAD> tag. By default,
text includes a default in-line cascading style sheet and title.
If text includes spaces, it must be enclosed in quotes. SQL*Plus does not test this free
text entry for HTML validity. You must ensure that the text you enter is valid for the
HTML <HEAD> tag. This gives you the flexibility to customize output for your browser
or special needs.
BODY text
The BODY text option enables you to specify attributes for the <BODY> tag. By
default, there are no attributes. If text includes spaces, it must be enclosed in quotes.
SQL*Plus does not test this free text entry for HTML validity. You must ensure that the
text you enter is valid for the HTML <BODY> tag. This gives you the flexibility to
customize output for your browser or special needs.
TABLE text
3-9
Chapter 3
SQL*Plus Program Syntax
The TABLE text option enables you to enter attributes for the <TABLE> tag. You can
use TABLE text to set HTML <TABLE> tag attributes such as BORDER,
CELLPADDING, CELLSPACING and WIDTH. By default, the <TABLE> WIDTH
attribute is set to 90% and the BORDER attribute is set to 1.
If text includes spaces, it must be enclosed in quotes. SQL*Plus does not test this free
text entry for HTML validity. You must ensure that the text you enter is valid for the
HTML <TABLE> tag. This gives you the flexibility to customize output for your browser
or special needs.
ENTMAP {ON|OFF}
ENTMAP ON or OFF specifies whether or not SQL*Plus replaces special characters <,
>, " and & with the HTML entities <, >, " and & respectively. ENTMAP
is set ON by default.
You can turn ENTMAP ON and OFF as required during a session. For example, with
ENTMAP OFF, SQL*Plus screen output is:
SQL>PROMPT A > B
A > B
As entities in the <HEAD> and <BODY> tags are not mapped, you must ensure that
valid entities are used in the MARKUP HEAD and BODY options.
If entities are not mapped, web browsers may treat data as invalid HTML and all
subsequent output may display incorrectly. ENTMAP OFF enables users to write their
own HTML tags to customize output.
Note:
ENTMAP only takes effect when the HTML option is set ON. For more
information about using entities in your output, see the COLUMN command.
SPOOL {ON|OFF}
SPOOL ON or OFF specifies whether or not SQL*Plus writes the HTML opening tags,
<HTML> and <BODY>, and the closing tags, </BODY> and </HTML>, to the start and
end of each file created by the SQL*Plus SPOOL filename command. The default is
OFF.
You can turn SPOOL ON and OFF as required during a session.
3-10
Chapter 3
SQL*Plus Program Syntax
Note:
It is important to distinguish between the SET MARKUP HTML SPOOL option,
and the SQLPLUS SPOOL filename command.
The SET MARKUP HTML SPOOL ON option enables the writing of the
<HTML> tag to the spool file. The spool file is not created, and the header and
footer tags enabled by the SET MARKUP HTML SPOOL ON option are not
written to the spool file until you issue the SQLPLUS SPOOL filename
command. See the SPOOL command for more information.
SQL*Plus writes several HTML tags to the spool file when you issue the SPOOL
filename command.
When you issue any of the SQL*Plus commands: EXIT, SPOOL OFF or SPOOL
filename, SQL*Plus appends the following end tags and closes the file:
</BODY>
</HTML>
You can specify <HEAD> tag contents and <BODY> attributes using the HEAD and
BODY options
PRE[FORMAT] {ON|OFF}
Note:
To produce report output using the HTML <PRE> tag, you must set
PREFORMAT ON. For example:
SQLPLUS -M "HTML ON PREFORMAT ON"
or
SET MARKUP HTML ON PREFORMAT ON
3-11
Chapter 3
SQL*Plus Program Syntax
• LINESIZE may have an effect on data if wrapping is on, or for very long data.
Depending on data size, output may be generated on separate lines, which a
browser may interpret as a space character.
• TTITLE and BTITLE content is output to three line positions: left, center and right,
and the maximum line width is preset to 90% of the browser window. These
elements may not align with the main output as expected due to the way they are
handled for web output. Entity mapping in TTITLE and BTITLE is the same as the
general ENTMAP setting specified in the MARKUP command.
• If you use a title in your output, then SQL*Plus starts a new HTML table for output
rows that appear after the title. Your browser may format column widths of each
table differently, depending on the width of data in each column.
• SET COLSEP, RECSEP and UNDERLINE only produce output in HTML reports
when PREFORMAT is ON.
MARKUP CSV ON
When MARKUP CSV ON is used, output from a query will be displayed in CSV format.
You can enable CSV markup while logging into a user session, by using the -
M[ARKUP] CSV ON option at the SQL*Plus command line. For more information, see
SQL*Plus Program Syntax. While logged in to a user session, you can enable CSV
markup by using the SET MARKUP CSV ON command.
You can specify the delimiter character by using the DELIMITER option. You can also
output text without quotes by using QUOTE OFF.
The last login time for non-SYS users is displayed when you log on. This feature is on
by default. The last login time is displayed in local time format. You can use the -
nologintime option to disable this security feature. After you login, the last login
information is displayed
SQL*Plus: Release 12.2.0.1.0 Production on Wed Jul 6 18:33:32 2016
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, Data Mining and Real Application
Last login time does not show when making a connection with the CONNECT
command.
Enables you to disable certain commands that interact with the operating system. This
is similar to disabling the same commands in the Product User Profile (PUP) table.
However, commands disabled with the -RESTRICT option are disabled even if there is
no connection to a server, and remain disabled until SQL*Plus terminates.
3-12
Chapter 3
SQL*Plus Program Syntax
If no -RESTRICT option is active, than all commands can be used, unless disabled in
the PUP table.
If -RESTRICT 3 is used, then LOGIN.SQL is not read. GLOGIN.SQL is read but
restricted commands used will fail.
Suppresses all SQL*Plus information and prompt messages, including the command
prompt, the echoing of commands, and the banner normally displayed when you start
SQL*Plus. If you omit username or password, SQL*Plus prompts for them, but the
prompts are not visible! Use SILENT to invoke SQL*Plus within another program so
that the use of SQL*Plus is invisible to the user.
SILENT is a useful mode for creating reports for the web using the SQLPLUS -
MARKUP command inside a CGI script or operating system script. The SQL*Plus
banner and prompts are suppressed and do not appear in reports created using the
SILENT option.
3.5.1.11 AC Option
-AC
Sets the Application Continuity flag for the session. For more information about
Application Continuity, see the Oracle Call Interface Programmer's Guide.
3.5.2 Logon
username[/password]
Represent the username and password with which you wish to start SQL*Plus and
connect to Oracle Database.
WARNING:
Including your password in plain text is a security risk. You can avoid this risk
by omitting the password, and entering it only when the system prompts for it.
3-13
Chapter 3
SQL*Plus Program Syntax
If you omit username and password, SQL*Plus prompts you for them. If you omit only
password, SQL*Plus prompts for it. In silent mode, username and password prompts
are not visible! Your username appears when you type it, but not your password.
@connect_identifier
Consists of an Oracle Net connect identifier. The exact syntax depends upon the
Oracle Net configuration. For more information, refer to the Oracle Net manual or
contact your DBA.
edition=value
The value for the Oracle Edition. An edition enables two or more versions of an object
in a database. It provides a staging area where changed objects can be loaded into
the database, compiled, and executed during uptime. This is particularly useful to
reduce downtime associated with patching an application. edition=value overrides any
edition value specified in the ORA_EDITION environment variable. For more detailed
information, see Using Edition-Based Redefinition.
/
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. Note that the prefix "OPS$" can be set to any other string of text.
For example, you may wish to change the settings in your INIT.ORA parameters file to
LOGONname or USERIDname. See Using Operating System Authentication for
information about operating system authentication.
AS {SYSASM |SYSBACKUP |SYSDBA |SYSDG |SYSOPER |SYSRAC |SYSKM}
The AS clause enables privileged connections by users who have been granted
SYSASM, SYSBACKUP, SYSDBA, SYSDG, SYSOPER, SYSRAC or SYSKM system
privileges.
/NOLOG
3.5.3 Start
@{url|file_name[.ext]} [arg ...]
Specifies the name of a script and arguments to run. The script can be called from the
local file system or from a web server.
SQL*Plus passes the arguments to the script as if executing the file using the
SQL*Plus START command. If no file suffix (file extension) is specified, the suffix
defined by the SET SUFFIX command is used. The default suffix is .sql.
See the START command for more information.
3-14
Part II
Using SQL*Plus
Part II helps you learn how to use SQL*Plus, how to tune SQL*Plus for better
performance, how to restrict access to tables and commands and provides overviews
of database administration tools and globalization support.
Part II contains the following chapters:
• SQL*Plus Basics
• Using Scripts in SQL*Plus
• Formatting SQL*Plus Reports
• Generating HTML Reports from SQL*Plus
• Tuning SQL*Plus
• SQL*Plus Security
• Database Administration with SQL*Plus
• SQL*Plus Globalization Support
4
SQL*Plus Basics
This chapter helps you learn the basics of using SQL*Plus. It has the following topics:
• About Entering and Executing Commands
• About Listing a Table Definition
• About Listing PL/SQL Definitions
• Running SQL Commands
• About Running PL/SQL Blocks
• Running SQL*Plus Commands
• System Variables that Affect How Commands Run
• About Stopping a Command while it is Running
• About Running Operating System Commands
• About Pausing the Display
• About Saving Changes to the Database Automatically
• About Interpreting Error Messages
4-1
Chapter 4
About Listing a Table Definition
Note:
DESCRIBE accesses information in the Oracle Database data dictionary. You
can also use SQL SELECT commands to access this and other information in
the database. See your Oracle Database SQL Language Reference for
details.
4-2
Chapter 4
About Listing PL/SQL Definitions
FUNCTION created.
DESCRIBE afunc
If you make a mistake, use Backspace to erase it and re-enter. When you are
done, press Return to move to the next line.
2. SQL*Plus displays a "2", the prompt for the second line. Enter the second line of
the command:
FROM EMP_DETAILS_VIEW WHERE SALARY > 12000;
The semicolon (;) means that this is the end of the command. Press Return or
click Execute. SQL*Plus processes the command and displays the results:
EMPLOYEE_ID LAST_NAME JOB_ID SALARY
----------- ------------------------- ---------- --------------
100 King AD_PRES $24,000
4-3
Chapter 4
Running SQL Commands
6 rows selected.
After displaying the results and the number of rows retrieved, SQL*Plus command-
line displays the command prompt again. If you made a mistake and therefore did
not get the results shown, re-enter the command.
The headings may be repeated in your output, depending on the setting of a
system variable called PAGESIZE. Sometimes, the result from a query will not fit
the available page width. You can use the system variable, LINESIZE, to set the
width of the output in characters. See Setting Page Dimensions. Typically,
LINESIZE is set to 80 in command-line. Whether you see the message stating the
number of records retrieved depends on the setting of the system variable,
FEEDBACK. See System Variables that Affect How Commands Run for more
information.
Example 4-3 Entering a SQL Command
In this example, you will enter and execute a SQL command to display the employee
number, name, job, and salary of each employee in the EMP_DETAILS_VIEW view.
In this guide, you will find most SQL commands divided into clauses, one clause on
each line. In Example 4-3, for instance, the SELECT and FROM clauses were placed
on separate lines. Many people find this clearly visible structure helpful, but you may
choose whatever line division makes commands most readable to you.
4-4
Chapter 4
About Running PL/SQL Blocks
A semicolon (;) tells SQL*Plus that you want to run the command. Type the semicolon
at the end of the last line of the command, as shown in Example 4-3, and press Return
or click Execute. SQL*Plus processes the command and also stores the command in
the SQL buffer. See The SQL Buffer for details. If you mistakenly press Return before
typing the semicolon, SQL*Plus prompts you with a line number for the next line of
your command. Type the semicolon and press Return again or click Execute to run the
command.
A slash (/) on a line by itself also tells SQL*Plus that you wish to run the command.
Press Return at the end of the last line of the command. SQL*Plus prompts you with
another line number. Type a slash and press Return again or click Execute. SQL*Plus
executes the command and stores it in the buffer.
A blank line in a SQL statement or script tells SQL*Plus that you have finished
entering the command, but do not want to run it yet. Press Return at the end of the last
line of the command. SQL*Plus prompts you with another line number.
Note:
You can change the way blank lines appear and behave in SQL statements
using the SET SQLBLANKLINES command. For more information about
changing blank line behavior, see the SET command.
To execute commands this way, press Return again; SQL*Plus now prompts you with
the SQL*Plus command prompt. SQL*Plus does not execute the command, but stores
it in the SQL buffer. See The SQL Buffer for details. If you subsequently enter another
SQL command, SQL*Plus overwrites the previous command in the buffer.
4-5
Chapter 4
About Running PL/SQL Blocks
SQL*Plus sends the complete PL/SQL subprogram to Oracle Database for processing
(as it does SQL commands). See your Oracle Database PL/SQL Language Reference
for more information.
You might enter and execute a PL/SQL subprogram as follows:
DECLARE
x NUMBER := 100;
BEGIN
FOR i IN 1..10 LOOP
IF MOD (i, 2) = 0 THEN --i is even
INSERT INTO temp VALUES (i, x, 'i is even');
ELSE
INSERT INTO temp VALUES (i, x, 'i is odd');
END IF;
x := x + 100;
END LOOP;
END;
.
/
4-6
Chapter 4
Running SQL*Plus Commands
If you make a mistake, use Backspace to erase it and re-enter. When you have
entered the line, press Return. SQL*Plus notes the new format and displays the
SQL*Plus command prompt again, ready for a new command.
2. Enter the following query and press Return to run it:
SELECT EMPLOYEE_ID, LAST_NAME, JOB_ID, SALARY
FROM EMP_DETAILS_VIEW WHERE SALARY > 12000;
6 rows selected.
Example 4-4 Entering a SQL*Plus Command
This example shows how you might enter a SQL*Plus command to change the format
used to display the column SALARY of the sample view, EMP_DETAILS_VIEW.
The COLUMN command formatted the column SALARY with a dollar sign ($) and a
comma (,) and gave it a new heading.
4-7
Chapter 4
System Variables that Affect How Commands Run
To ensure that the statement is interpreted correctly, reposition the hyphen from the
end of the first line to the beginning of the second line.
4-8
Chapter 4
About Running Operating System Commands
Note:
Pressing Cancel does not stop the printing of a file that you have sent to a
printer with the OUT clause of the SQL*Plus SPOOL command. (You will learn
about printing query results in Formatting SQL*Plus Reports.) You can stop
the printing of a file through your operating system. For more information, see
your operating system's installation and user's guide.
When the command finishes running, the SQL*Plus command prompt appears again.
Note:
Operating system commands entered from a SQL*Plus session using the
HOST command do not affect the current SQL*Plus session. For example,
setting an operating system environment variable does not affect the current
SQL*Plus session, but may affect SQL*Plus sessions started subsequently.
You can suppress access to the HOST command. For more information about
suppressing the HOST command see SQL*Plus Security.
4-9
Chapter 4
About Saving Changes to the Database Automatically
See Also:
SET EXITC[OMMIT] {ON | OFF}
COMMIT COMPLETE
When the autocommit feature is turned on, you cannot roll back changes to the
database.
To commit changes to the database after a number of SQL DML commands, for
example, 10, enter
SET AUTOCOMMIT 10
SQL*Plus counts SQL DML commands as they are executed and commits the
changes after each 10th SQL DML command.
Note:
For this feature, a PL/SQL block is regarded as one transaction, regardless of
the actual number of SQL commands contained within it.
To turn the autocommit feature off again, enter the following command:
SET AUTOCOMMIT OFF
To confirm that AUTOCOMMIT is now set to OFF, enter the following SHOW
command:
SHOW AUTOCOMMIT
AUTOCOMMIT OFF
Alternatively, you can enter the following to turn the autocommit feature on:
SET AUTOCOMMIT IMMEDIATE
4-10
Chapter 4
About Interpreting Error Messages
You will often be able to figure out how to correct the problem from the message
alone. If you need further explanation, take one of the following steps to determine the
cause of the problem and how to correct it:
• If the error is a numbered error beginning with the letters "SP2", look up the
SQL*Plus message in SQL*Plus Error Messages.
• If the error is a numbered error beginning with the letters "CPY" look up the
SQL*Plus COPY command message in COPY Command Messages.
• If the error is a numbered error beginning with the letters "ORA", look up the
Oracle Database message in the Oracle Database Error Messages guide or in the
platform-specific Oracle documentation provided for your operating system.
• If the error is a numbered error beginning with the letters "PLS", look up the Oracle
Database message in the Oracle Database PL/SQL Language Reference.
If the error is unnumbered, look up correct syntax for the command that generated the
error in SQL*Plus Command Reference for a SQL*Plus command, in the Oracle
Database SQL Language Reference for a SQL command, or in the Oracle Database
PL/SQL Language Reference for a PL/SQL block. Otherwise, contact your DBA.
Example 4-6 Interpreting an Error Message
If you attempt to execute a file that does not exist or is unavailable by entering:
START EMPLYYES.SQL
4-11
5
Using Scripts in SQL*Plus
This chapter helps you learn to write and edit scripts containing SQL*Plus commands,
SQL commands, and PL/SQL blocks. It covers the following topics:
• About Editing Scripts
• About Editing Scripts in SQL*Plus Command-Line
• About Placing Comments in Scripts
• Running Scripts
• Nesting Scripts
• About Exiting from a Script with a Return Code
• Defining Substitution Variables
• About Using Predefined Variables
• Using Substitution Variables
• Passing Parameters through the START Command
• About Communicating with the User
• About Using Bind Variables
• Fetching Iterative Results from a SELECT inside a PL/SQL Block
Read this chapter while sitting at your computer and try out the examples shown.
Before beginning, make sure you have access to the sample schema described in
SQL*Plus Overview.
5-1
Chapter 5
About Editing Scripts in SQL*Plus Command-Line
You can include an editor definition in your user or site profile so that it is always
enabled when you start SQL*Plus. See SQL*Plus Configuration, and the DEFINE and
EDIT commands for more information.
To create a script with a text editor, enter EDIT followed by the name of the file to edit
or create, for example:
EDIT SALES
EDIT adds the filename extension .SQL to the name unless you specify the file
extension. When you save the script with the text editor, it is saved back into the same
file. EDIT lets you create or modify scripts.
You must include a semicolon at the end of each SQL command and a slash (/) on a
line by itself after each PL/SQL block in the file. You can include multiple SQL
commands and PL/SQL blocks in a script.
Example 5-1 Using a System Editor to Write a SQL Script
Suppose you have composed a query to display a list of salespeople and their
commissions. You plan to run it once a month to keep track of how well each
employee is doing.
To compose and save the query using your system editor, invoke your editor and
create a file to hold your script:
EDIT SALES
Enter each of the following lines in your editor. Do not forget to include the semicolon
at the end of the SQL statement:
COLUMN LAST_NAME HEADING 'LAST NAME'
COLUMN SALARY HEADING 'MONTHLY SALARY' FORMAT $99,999
COLUMN COMMISSION_PCT HEADING 'COMMISSION %' FORMAT 90.90
SELECT LAST_NAME, SALARY, COMMISSION_PCT
FROM EMP_DETAILS_VIEW
WHERE JOB_ID='SA_MAN';
The format model for the column COMMISSION_PCT tells SQL*Plus to display an
initial zero for decimal values, and a zero instead of a blank when the value of
COMMISSION_PCT is zero for a given row. Format models and the COLUMN
command are described in more detail in the COLUMN command and in Format
Models.
Now use your editor's save command to store your query in a file called SALES.SQL.
5-2
Chapter 5
About Editing Scripts in SQL*Plus Command-Line
lists line n
LIST n L n or n
These are useful if you want to correct or modify a command you have entered.
5-3
Chapter 5
About Editing Scripts in SQL*Plus Command-Line
Notice that the semicolon you entered at the end of the SELECT command is not
listed. This semicolon is necessary to indicate the end of the command when you
enter it, but it is not part of the SQL command and SQL*Plus does not store it in the
SQL buffer.
Example 5-2 Listing the Buffer Contents
Suppose you want to list the current command. Use the LIST command as shown. (If
you have exited SQL*Plus or entered another SQL command or PL/SQL block since
following the steps in Example 4-3, perform the steps in that example again before
continuing.)
LIST
Examine the error message; it indicates an invalid column name in line 1 of the query.
The asterisk shows the point of error—the mis-typed column JOB_ID.
Instead of re-entering the entire command, you can correct the mistake by editing the
command in the buffer. The line containing the error is now the current line. Use the
CHANGE command to correct the mistake. This command has three parts, separated
by slashes or any other non-alphanumeric character:
• the word CHANGE or the letter C
• the sequence of characters you want to change
• the replacement sequence of characters
The CHANGE command finds the first occurrence in the current line of the character
sequence to be changed and changes it to the new sequence. You do not need to use
the CHANGE command to re-enter an entire line.
5-4
Chapter 5
About Editing Scripts in SQL*Plus Command-Line
Now that you have corrected the error, you can use the RUN command to run the
command again:
RUN
Note that the column SALARY retains the format you gave it in Example 4-4. (If you
have left SQL*Plus and started again since performing Example 4-4 the column has
reverted to its original format.)
See CHANGE for information about the significance of case in a CHANGE command
and on using wildcards to specify blocks of text in a CHANGE command.
Example 5-3 Making an Error in Command Entry
Suppose you try to select the JOB_ID column but mistakenly enter it as JO_ID. Enter
the following command, purposely misspelling JOB_ID in the first line:
SELECT EMPLOYEE_ID, LAST_NAME, JO_ID, SALARY
FROM EMP_DETAILS_VIEW
WHERE JOB_ID='SA_MAN';
2. Enter APPEND followed by the text you want to add. If the text you want to add
begins with a blank, separate the word APPEND from the first character of the text
by two blanks: one to separate APPEND from the text, and one to go into the
buffer with the text.
5-5
Chapter 5
About Editing Scripts in SQL*Plus Command-Line
4* ORDER BY SALARY
Next, enter the following command (be sure to type two spaces between APPEND and
DESC):
APPEND DESC
Press Return again to indicate that you will not enter any more lines, and then use
RUN to verify and re-run the query.
1 SELECT EMPLOYEE_ID, LAST_NAME, JOB_ID, SALARY
2 FROM EMP_DETAILS_VIEW
3 WHERE JOB_ID='SA_MAN'
4* ORDER BY SALARY
5-6
Chapter 5
About Placing Comments in Scripts
DEL makes the following line of the buffer (if any) the current line.
See DEL for more information.
5-7
Chapter 5
About Placing Comments in Scripts
5.3.3 Using - -
You can use ANSI/ISO "- -" style comments within SQL statements, PL/SQL blocks, or
SQL*Plus commands. Since there is no ending delimiter, the comment cannot span
multiple lines.
For PL/SQL and SQL, enter the comment after a command on a line, or on a line by
itself:
-- Commissions report to be run monthly
DECLARE --block for reporting monthly sales
For SQL*Plus commands, you can only include "- -" style comments if they are on a
line by themselves. For example, these comments are legal:
-- set maximum width for LONG to 777
SET LONG 777
5-8
Chapter 5
About Placing Comments in Scripts
CREATE OR REPLACE
2 /* HELLO */
3 PROCEDURE HELLO AS
4 BEGIN
5 DBMS_OUTPUT.PUT_LINE('HELLO');
6 END;
7 /
The location of the comment prevents SQL*Plus from recognizing the command
as a command. SQL*Plus submits the PL/SQL block to the server when it sees the
slash "/" at the beginning of the comment, which it interprets as the "/" statement
terminator. Move the comment to avoid this error. For example:
CREATE OR REPLACE PROCEDURE
2 /* HELLO */
3 HELLO AS
4 BEGIN
5 DBMS_OUTPUT.PUT_LINE('HELLO');
6 END;
7 /
Procedure created.
2. Do not put comments after statement terminators (period, semicolon or slash). For
example, if you enter:
SELECT 'Y' FROM DUAL; -- TESTING
5-9
Chapter 5
Running Scripts
REGION_NAME CITY
------------------------- ------------------------------
Americas Seattle
Americas Seattle
Americas Seattle
Europe Oxford
Europe Oxford
Americas Toronto
6 rows selected.
You can SET DEFINE OFF to prevent scanning for the substitution character.
For more information on substitution and termination characters, see DEFINE,
SQLTERMINATOR and SQLBLANKLINES in the SET command.
You can also use the @ (at sign) command to run a script:
@SALES
The @ and @@ commands list and run the commands in the specified script in the
same manner as START. SET ECHO affects the @ and @@ commands in the same
way as it affects the START command.
To see the commands as SQL*Plus "enters" them, you can SET ECHO ON. The
ECHO system variable controls the listing of the commands in scripts run with the
START, @ and @@ commands. Setting the ECHO variable OFF suppresses the
listing.
START, @ and @@ leave the last SQL command or PL/SQL block of the script in the
buffer.
Example 5-7 Running a Script
To retrieve and run the command stored in SALES.SQL, enter
5-10
Chapter 5
Nesting Scripts
START SALES
SQL*Plus runs the commands in the file SALES and displays the results of the
commands on your screen, formatting the query results according to the SQL*Plus
commands in the file:
SQL*Plus starts, prompts for your password and runs the script.
• Include your username as the first line of the file. Follow the SQLPLUS command
with @ and the filename. SQL*Plus starts, prompts for your password and runs the
file.
Note:
The @@ command may be useful in this example. See the @@ (double at
sign) command for more information.
5-11
Chapter 5
Defining Substitution Variables
To list all substitution variable definitions, enter DEFINE by itself. Note that any
substitution variable you define explicitly through DEFINE takes only CHAR values
(that is, the value you assign to the variable is always treated as a CHAR datatype).
You can define a substitution variable of datatype NUMBER implicitly through the
ACCEPT command. You will learn more about the ACCEPT command.
To delete a substitution variable, use the SQL*Plus command UNDEFINE followed by
the variable name.
Example 5-8 Defining a Substitution Variable
To define a substitution variable L_NAME and give it the value "SMITH", enter the
following command:
DEFINE L_NAME = SMITH
To confirm the variable definition, enter DEFINE followed by the variable name:
DEFINE L_NAME
See Also:
Predefined Variables for a list of the predefined variables and examples of
their use.
5-12
Chapter 5
Using Substitution Variables
as if they were
SELECT JOB_ID, SALARY
FROM EMP_DETAILS_VIEW
WHERE SALARY>12000;
5-13
Chapter 5
Using Substitution Variables
JOB_ID MAXIMUM
---------- ----------
AC_ACCOUNT 8300
AC_MGR 12000
AD_ASST 4400
AD_PRES 24000
AD_VP 17000
FI_ACCOUNT 9000
FI_MGR 12000
HR_REP 6500
IT_PROG 9000
MK_MAN 13000
MK_REP 6000
JOB_ID MAXIMUM
---------- ----------
PR_REP 10000
PU_CLERK 3100
PU_MAN 11000
SA_MAN 14000
SA_REP 11500
SH_CLERK 4200
ST_CLERK 3600
ST_MAN 8200
19 rows selected.
If you wish to append characters immediately after a substitution variable, use a period
to separate the variable from the character. For example:
SELECT SALARY FROM EMP_DETAILS_VIEW WHERE EMPLOYEE_ID='&X.5';
Enter value for X: 20
is interpreted as
SELECT SALARY FROM EMP_DETAILS_VIEW WHERE EMPLOYEE_ID='205';
5-14
Chapter 5
Using Substitution Variables
2* MAX(&NUMBER_COL) MAXIMUM
APPEND ,
2* MAX(&NUMBER_COL) MAXIMUM,
CHANGE/&/&&
2* MAX(&&NUMBER_COL) MAXIMUM,
3i
4i
SUM(&&NUMBER_COL) TOTAL,
5i
AVG(&&NUMBER_COL) AVERAGE
6i
1* SELECT &GROUP_COL,
CHANGE/&/&&
1* SELECT &&GROUP_COL,
7* GROUP BY &GROUP_COL
CHANGE/&/&&/
7* GROUP BY &&GROUP_COL
SAVE STATS2
Finally, run the script STATS2 and respond to the prompts as follows:
5-15
Chapter 5
Using Substitution Variables
START STATS2
Enter value for group_col: JOB_ID
Enter value for number_col: SALARY
Enter value for table: EMP_DETAILS_VIEW
19 rows selected.
Note that you were prompted for the values of NUMBER_COL and GROUP_COL only
once. If you were to run STATS2 again during the current session, you would be
prompted for TABLE (because its name has a single ampersand and the variable is
therefore not DEFINEd) but not for GROUP_COL or NUMBER_COL (because their
names have double ampersands and the variables are therefore DEFINEd).
Before continuing, set the system variable VERIFY back to ON:
SET VERIFY ON
5.9.3 Restrictions
You cannot use substitution variables in the buffer editing commands, APPEND,
CHANGE, DEL, and INPUT, nor in other commands where substitution would be
5-16
Chapter 5
Passing Parameters through the START Command
meaningless. The buffer editing commands, APPEND, CHANGE, and INPUT, treat
text beginning with "&" or "&&" literally, like any other text string.
In the following START command, SQL*Plus would substitute PU_CLERK for &1 and
3100 for &2 in the script MYFILE:
START MYFILE PU_CLERK 3100
When you use arguments with the START command, SQL*Plus DEFINEs each
parameter in the script with the value of the appropriate argument.
1 COLUMN LAST_NAME HEADING 'LAST NAME'
2 COLUMN SALARY HEADING 'MONTHLY SALARY' FORMAT $99,999
5-17
Chapter 5
About Communicating with the User
6* WHERE JOB_ID='SA_MAN'
CHANGE /SA_MAN/&1
6* WHERE JOB_ID='&1'
SAVE ONEJOB
SQL*Plus lists the line of the SQL command that contains the parameter, before and
after replacing the parameter with its value, and then displays the output:
old 3: WHERE JOB_ID='&1'
new 3: WHERE JOB_ID='SA_MAN'
You can use many parameters in a script. Within a script, you can refer to each
parameter many times, and you can include the parameters in any order.
While you cannot use parameters when you run a command with RUN or slash (/), you
could use substitution variables instead.
Before continuing, return the columns to their original heading by entering the following
command:
CLEAR COLUMN
5-18
Chapter 5
About Communicating with the User
The TTITLE command sets the top title for your report. See About Defining Page and
Report Titles and Dimensions for more information about the TTITILE command.
Finally, run the script, responding to the prompt for the title as shown:
START PROMPT1
SAVE PROMPT1
5-19
Chapter 5
About Communicating with the User
Employee ID. :
205
Department Report
What would happen if you typed characters instead of numbers? Since you specified
NUMBER after the variable name in the ACCEPT command, SQL*Plus will not accept
a non-numeric value:
Try entering characters instead of numbers to the prompt for "Employee ID.",
SQL*Plus will respond with an error message and prompt you again to re-enter the
correct number:
START PROMPT2
When SQL*Plus prompts you to enter an Employee ID, enter the word "one" instead of
a number:
Enter a valid employee ID
For Example 145, 206
Employee ID. :
one
Save this file as PROMPT2. Next, run this script. SQL*Plus prompts for the value of
ENUMBER using the text you specified with PROMPT and ACCEPT:
START PROMPT2
5-20
Chapter 5
About Using Bind Variables
Before continuing to the next section, reset all columns to their original formats and
headings by entering the following command:
CLEAR COLUMNS
This command creates a bind variable named ret_val with a datatype of NUMBER.
See the VARIABLE command for more information. (To list all bind variables created
in a session, type VARIABLE without any arguments.)
5-21
Chapter 5
About Using Bind Variables
To change this bind variable in SQL*Plus, you must enter a PL/SQL block. For
example:
BEGIN
:ret_val:=4;
END;
/
RET_VAL
----------
4
This command displays a bind variable named ret_val. See PRINT for more
information about displaying bind variables.
:ABC
----------
4
SQL>
Table created.
1 row created.
COL1 COL2
---------- ----------
123 test
SQL>
5-22
Chapter 5
Using REFCURSOR Bind Variables
The results from the SELECT statement can now be displayed in SQL*Plus with the
PRINT command.
PRINT employee_info
EMPLOYEE_ID SALARY
----------- ----------
145 14000
146 13500
147 12000
148 11000
149 10500
The PRINT statement also closes the cursor. To reprint the results, the PL/SQL block
must be executed again before using PRINT.
Package created.
Next, create the stored procedure containing an OPEN... FOR SELECT statement.
CREATE OR REPLACE PACKAGE BODY EmpPack AS
PROCEDURE EmpInfoRpt (emp_cv IN OUT EmpInfoTyp) AS
BEGIN
OPEN emp_cv FOR SELECT EMPLOYEE_ID, SALARY
FROM EMP_DETAILS_VIEW
WHERE JOB_ID='SA_MAN' ;
END;
END;
/
Procedure created.
EMPLOYEE_ID SALARY
----------- ----------
145 14000
146 13500
5-23
Chapter 5
Using REFCURSOR Bind Variables
147 12000
148 11000
149 10500
The procedure can be executed multiple times using the same or a different
REFCURSOR bind variable.
VARIABLE pcv REFCURSOR
EXECUTE EmpInfo_rpt(:pcv)
PRINT pcv
EMPLOYEE_ID SALARY
----------- ----------
145 14000
146 13500
147 12000
148 11000
149 10500
Function created.
EMPLOYEE_ID SALARY
----------- ----------
145 14000
146 13500
147 12000
148 11000
149 10500
The function can be executed multiple times using the same or a different
REFCURSOR bind variable.
EXECUTE :rc := EmpInfo_fn
5-24
Chapter 5
Fetching Iterative Results from a SELECT inside a PL/SQL Block
Next, enter a PL/SQL block that uses the bind variable in an OPEN... FOR SELECT
statement. This statement opens a cursor variable and executes a query. See OPEN
Statementfor information on the OPEN command and cursor variables.
In this example we are binding the SQL*Plus employee_info bind variable to the cursor
variable.
BEGIN
OPEN :employee_info FOR SELECT EMPLOYEE_ID, SALARY
FROM EMP_DETAILS_VIEW WHERE JOB_ID='SA_MAN' ;
END;
/
5-25
Chapter 5
Fetching Iterative Results from a SELECT inside a PL/SQL Block
30 SALES CHICAGO
40 OPERATIONS BOSTON
4 rows selected
ResultSet #2
14 rows selected
Next, run the procedure to retrieve results iteratively from the SELECT statements in
the procedure.
exec p4
PL/SQL procedure successfully completed.
5-26
6
Formatting SQL*Plus Reports
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:
• About Formatting Columns
• About Clarifying Your Report with Spacing and Summary Lines
• About Defining Page and Report Titles and Dimensions
• About Storing and Printing Query Results
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 .
6-1
Chapter 6
About Formatting Columns
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.)
LAST MONTHLY
NAME SALARY COMMISSION
------------------------- ---------- ----------
Russell 14000 .4
Partners 13500 .3
Errazuriz 12000 .3
Cambrault 11000 .3
Zlotkey 10500 .2
LAST MONTHLY
NAME SALARY COMMISSION
========================= ========== ==========
Russell 14000 .4
Partners 13500 .3
Errazuriz 12000 .3
Cambrault 11000 .3
Zlotkey 10500 .2
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.
6-2
Chapter 6
About Formatting Columns
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
6-3
Chapter 6
About Formatting Columns
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.
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.
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
or exit from SQL*Plus. Datatypes, in this manual, include the following types:
• CHAR
• NCHAR
• VARCHAR2 (VARCHAR)
• NVARCHAR2 (NCHAR VARYING)
• DATE
• LONG
• BLOB
BFILE
• CLOB
• NCLOB
• XMLType
6-4
Chapter 6
About Formatting Columns
If you specify a width shorter than the column heading, SQL*Plus truncates the
heading. See the COLUMN command for more details.
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. 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
6-5
Chapter 6
About Formatting Columns
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.
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.
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
/
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>'));
6-6
Chapter 6
About Formatting Columns
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;
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
columns cleared
6-7
Chapter 6
About Formatting Columns
CLEAR COLUMNS
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
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
6-8
Chapter 6
About Clarifying Your Report with Spacing and Summary Lines
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
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
6-9
Chapter 6
About Clarifying Your Report with Spacing and Summary Lines
for all departments. You could also print summary lines containing the average,
maximum, minimum, standard deviation, variance, or row count.
Note:
Whenever you specify a column or expression in a BREAK command, use an
ORDER BY clause specifying the same column or expression. If you do not do
this, breaks occur every time the column value changes.
6 rows selected.
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;
6-10
Chapter 6
About Clarifying Your Report with Spacing and Summary Lines
80 Russell 14000
Partners 13500
90 King 24000
Kochhar 17000
De Haan 17000
6 rows selected.
Note:
SKIP PAGE does not cause a physical page break character to be generated
unless you have also specified NEWPAGE 0.
Page: 2
DEPARTMENT_ID JOB_ID LAST_NAME SALARY
------------- ---------- ------------------------- ----------
80 SA_MAN Russell 14000
Partners 13500
Page: 3
6-11
Chapter 6
About Clarifying Your Report with Spacing and Summary Lines
6 rows selected.
Now, to skip a page when the value of DEPARTMENT_ID changes and one line when
the value of JOB_ID changes, enter the following command:
BREAK ON DEPARTMENT_ID SKIP PAGE ON JOB_ID SKIP 1
To show that SKIP PAGE has taken effect, create a TTITLE with a page number:
TTITLE COL 35 FORMAT 9 'Page:' SQL.PNO
You can list your current break definition by entering the BREAK command with no
clauses:
BREAK
You can remove the current break definition by entering the CLEAR command with the
BREAKS clause:
CLEAR BREAKS
You may wish to place the command CLEAR BREAKS at the beginning of every script
to ensure that previously entered BREAK commands will not affect queries you run in
a given file.
6-12
Chapter 6
About Clarifying Your Report with Spacing and Summary Lines
BREAK ON break_column
COMPUTE function LABEL label_name OF column column column
... ON break_column
You can include multiple break columns and actions, such as skipping lines in the
BREAK command, as long as the column you name after ON in the COMPUTE
command also appears after ON in the BREAK command. To include multiple break
columns and actions in BREAK when using it in conjunction with COMPUTE, use
these commands in the following forms:
BREAK ON break_column_1 SKIP PAGE ON break_column_2 SKIP 1
COMPUTE function LABEL label_name OF column column column
... ON break_column_2
The function you specify in the COMPUTE command applies to all columns you enter
after OF and before ON. The computed values print on a separate line when the value
of the ordered column changes.
Labels for ON REPORT and ON ROW computations appear in the first column;
otherwise, they appear in the column specified in the ON clause.
You can change the compute label by using COMPUTE LABEL. If you do not define a
label for the computed value, SQL*Plus prints the unabbreviated function keyword.
The compute label can be suppressed by using the NOPRINT option of the COLUMN
command on the break column. See the COMPUTE command for more details. If you
6-13
Chapter 6
About Clarifying Your Report with Spacing and Summary Lines
use the NOPRINT option for the column on which the COMPUTE is being performed,
the COMPUTE result is also suppressed.
break on DEPARTMENT_ID page nodup
on JOB_ID skip 1 nodup
Now enter the following COMPUTE command and run the current query:
COMPUTE SUM OF SALARY ON DEPARTMENT_ID
/
6 rows selected.
To compute the sum of salaries for departments 10 and 20 without printing the
compute label:
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 SALARY>12000
ORDER BY DEPARTMENT_ID;
80 Russell 14000
80 Partners 13500
----------
27500
90 King 24000
90 Kochhar 17000
6-14
Chapter 6
About Clarifying Your Report with Spacing and Summary Lines
90 De Haan 17000
----------
58000
6 rows selected.
6 rows selected.
When you establish the format of a NUMBER column, you must allow for the size of
the sums included in the report.
Example 6-13 Computing and Printing Subtotals
To compute the total of SALARY by department, first list the current BREAK definition:
BREAK
LAST_NAME SALARY
------------------------- ----------
Russell 14000
Partners 13500
Errazuriz 12000
Cambrault 11000
Zlotkey 10500
----------
TOTAL 61000
To print a grand total (or grand average, grand maximum, and so on) in addition to
subtotals (or sub-averages, and so on), include a break column and an ON REPORT
6-15
Chapter 6
About Clarifying Your Report with Spacing and Summary Lines
clause in your BREAK command. Then, enter one COMPUTE command for the break
column and another to compute ON REPORT:
BREAK ON break_column ON REPORT
COMPUTE function LABEL label_name OF column ON break_column
COMPUTE function LABEL label_name OF column ON REPORT
APPEND , COMMISSION_PCT;
You can also print multiple summary lines on the same break column. To do so,
include the function for each summary line in the COMPUTE command as follows:
COMPUTE function LABEL label_name function
LABEL label_name function LABEL label_name ...
OF column ON break_column
If you include multiple columns after OF and before ON, COMPUTE calculates and
prints values for each column you specify.
DEPARTMENT_ID LAST_NAME SALARY
------------- ------------------------- ----------
30 Colmenares 2500
Himuro 2600
Tobias 2800
Baida 2900
Khoo 3100
6-16
Chapter 6
About Clarifying Your Report with Spacing and Summary Lines
Raphaely 11000
************* ----------
avg 4150
sum 24900
6 rows selected.
You do not have to enter a BREAK command; the BREAK you entered in
Example 6-14 is still in effect. Now, change the first line of the select query to include
COMMISSION_PCT:
1
Example 6-16 Computing Multiple Summary Lines on the Same Break Column
To compute the average and sum of salaries for the sales department, first enter the
following BREAK and COMPUTE commands:
BREAK ON DEPARTMENT_ID
COMPUTE AVG SUM OF SALARY ON DEPARTMENT_ID
breaks cleared
CLEAR COMPUTES
computes cleared
You may wish to place the commands CLEAR BREAKS and CLEAR COMPUTES at
the beginning of every script to ensure that previously entered BREAK and COMPUTE
commands will not affect queries you run in a given file.
Example 6-17 Removing COMPUTE Definitions
To remove all COMPUTE definitions and the accompanying BREAK definition, enter
the following commands:
CLEAR BREAKS
6-17
Chapter 6
About Defining Page and Report Titles and Dimensions
6.3.1 Setting the Top and Bottom Titles and Headers and Footers
As you have already seen, you can set a title to display at the top of each page of a
report. You can also set a title to display at the bottom of each page. The TTITLE
command defines the top title; the BTITLE command defines the bottom title.
You can also set a header and footer for each report. The REPHEADER command
defines the report header; the REPFOOTER command defines the report footer.
A TTITLE, BTITLE, REPHEADER or REPFOOTER command consists of the
command name followed by one or more clauses specifying a position or format and a
CHAR value you wish to place in that position or give that format. You can include
multiple sets of clauses and CHAR values:
TTITLE position_clause(s) char_value position_clause(s) char_value ...
BTITLE position_clause(s) char_value position_clause(s) char_value ...
REPHEADER position_clause(s) char_value position_clause(s) char_value ...
REPFOOTER position_clause(s) char_value position_clause(s) char_value ...
For descriptions of all TTITLE, BTITLE, REPHEADER and REPFOOTER clauses, see
the TTITLE command and the REPHEADER command.
ACME SALES DEPARTMENT PERSONNEL REPORT
DEPARTMENT_ID LAST_NAME SALARY
------------- ------------------------- ----------
30 Colmenares 2500
30 Himuro 2600
30 Tobias 2800
30 Baida 2900
30 Khoo 3100
30 Raphaely 11000
COMPANY CONFIDENTIAL
6 rows selected.
COMPANY CONFIDENTIAL
6-18
Chapter 6
About Defining Page and Report Titles and Dimensions
30 Tobias 2800
30 Baida 2900
30 Khoo 3100
30 Raphaely 11000
COMPANY CONFIDENTIAL
6 rows selected.
which displays the following two pages of output, with the new REPHEADER
displayed on the first page:
6-19
Chapter 6
About Defining Page and Report Titles and Dimensions
30 Khoo 3100
30 Raphaely 11000
COMPANY CONFIDENTIAL
6 rows selected.
The LEFT, RIGHT, and CENTER clauses place the following values at the beginning,
end, and center of the line. The SKIP clause tells SQL*Plus to move down one or
more lines.
Note that there is no longer any space between the last row of the results and the
bottom title. The last line of the bottom title prints on the last line of the page. The
amount of space between the last row of the report and the bottom title depends on
the overall page size, the number of lines occupied by the top title, and the number of
rows in a given page. In the above example, the top title occupies three more lines
than the top title in the previous example. You will learn to set the number of lines per
page later in this chapter.
To always print n blank lines before the bottom title, use the SKIP n clause at the
beginning of the BTITLE command. For example, to skip one line before the bottom
title in the example above, you could enter the following command:
BTITLE SKIP 1 CENTER 'COMPANY CONFIDENTIAL'
COMPANY CONFIDENTIAL
6 rows selected.
6-20
Chapter 6
About Defining Page and Report Titles and Dimensions
There are five system-maintained values you can display in titles, the most commonly
used of which is SQL.PNO (the current page number). See TTITLE for a list of system-
maintained values you can display in titles.
ACMEWIDGET PAGE: 1
COMPANY CONFIDENTIAL
6 rows selected.
Note that SQL.PNO has a format ten spaces wide. You can change this format with
the FORMAT clause of TTITLE (or BTITLE).
ACME WIDGET 'PAGE:' 1
6-21
Chapter 6
About Defining Page and Report Titles and Dimensions
COMPANY CONFIDENTIAL
6 rows selected.
These commands cause SQL*Plus to cease displaying titles on reports, but do not
clear the current definitions of the titles. You may restore the current definitions by
entering:
TTITLE ON
BTITLE ON
6-22
Chapter 6
About Defining Page and Report Titles and Dimensions
variable and referencing the variable in a TTITLE command. Use the following form of
the COLUMN command to define the variable:
COLUMN column_name NEW_VALUE variable_name
You must include the master column in an ORDER BY clause and in a BREAK
command using the SKIP PAGE clause.
Manager: 101
Manager: 201
6 rows selected.
If you want to print the value of a column at the bottom of the page, you can use the
COLUMN command in the following form:
COLUMN column_name OLD_VALUE variable_name
SQL*Plus prints the bottom title as part of the process of breaking to a new page—
after finding the new value for the master column. Therefore, if you simply referenced
the NEW_VALUE of the master column, you would get the value for the next set of
details. OLD_VALUE remembers the value of the master column that was in effect
before the page break began.
Example 6-24 Creating a Master/Detail Report
Suppose you want to create a report that displays two different managers' employee
numbers, each at the top of a separate page, and the people reporting to the manager
on the same page as the manager's employee number. First create a variable,
MGRVAR, to hold the value of the current manager's employee number:
COLUMN MANAGER_ID NEW_VALUE MGRVAR NOPRINT
Because you will only display the managers' employee numbers in the title, you do not
want them to print as part of the detail. The NOPRINT clause you entered above tells
SQL*Plus not to print the column MANAGER_ID.
Next, include a label and the value in your page title, enter the proper BREAK
command, and suppress the bottom title from the last example:
TTITLE LEFT 'Manager: ' MGRVAR SKIP 2
BREAK ON MANAGER_ID SKIP PAGE
BTITLE OFF
6-23
Chapter 6
About Defining Page and Report Titles and Dimensions
If you set NEWPAGE to zero, SQL*Plus skips zero lines and displays and prints a
formfeed character to begin a new page. On most types of computer screens, the
formfeed character clears the screen and moves the cursor to the beginning of the first
line. When you print a report, the formfeed character makes the printer move to the top
of a new sheet of paper, even if the overall page length is less than that of the paper. If
you set NEWPAGE to NONE, SQL*Plus does not print a blank line or formfeed
between report pages.
To set the number of lines on a page, use the PAGESIZE variable of the SET
command:
SET PAGESIZE number_of_lines
6-24
Chapter 6
About Defining Page and Report Titles and Dimensions
You may wish to reduce the line size to center a title properly over your output, or you
may want to increase line size for printing on wide paper. You can change the line
width using the LINESIZE variable of the SET command:
SET LINESIZE number_of_characters
6 rows selected.
To list the current values of these variables, use the SHOW command:
SHOW PAGESIZE
SHOW NEWPAGE
SHOW LINESIZE
Through the SQL*Plus command SPOOL, you can store your query results in a file or
print them on your computer's default printer.
Example 6-25 Setting Page Dimensions
To set the page size to 66 lines, clear the screen (or advance the printer to a new
sheet of paper) at the start of each page, and set the line size to 70, enter the following
commands:
SET PAGESIZE 66
SET NEWPAGE 0
SET LINESIZE 70
Now enter and run the following commands to see the results:
TTITLE CENTER 'ACME WIDGET PERSONNEL REPORT' SKIP 1 -
CENTER '01-JAN-2001' SKIP 2
6-25
Chapter 6
About Storing and Printing Query Results
If you do not follow the filename with a period and an extension, SPOOL adds a
default file extension to the filename to identify it as an output file. The default varies
with the operating system; on most hosts it is LST or LIS. The extension is not
appended when you spool to system generated files such as /dev/null and /dev/stderr.
See the platform-specific Oracle documentation provided for your operating system for
more information.
SQL*Plus continues to spool information to the file until you turn spooling off, using the
following form of SPOOL:
SPOOL OFF
After entering these commands, you use the SPOOL command as shown in the
previous section to create the flat file.
The SET COLSEP command may be useful to delineate the columns. For more
information, see the SET command.
SQL*Plus stores all information displayed on the screen after you enter the SPOOL
command in the file you specify.
6-26
Chapter 6
About Storing and Printing Query Results
SQL*Plus stops spooling and copies the contents of the spooled file to your
computer's standard (default) printer. SPOOL OUT does not delete the spool file after
printing.
A C M E W I D G E T
80 Russell $14,000
Partners $13,500
********** --------------
sum $27,500
90 King $24,000
Kochhar $17,000
De Haan $17,000
********** --------------
sum $58,000
--------------
sum $98,500
COMPANY CONFIDENTIAL
6 rows selected.
Next, enter the following commands into the file, using your text editor:
SPOOL TEMP
CLEAR COLUMNS
CLEAR BREAKS
CLEAR COMPUTES
6-27
Chapter 6
About Storing and Printing Query Results
SET PAGESIZE 24
SET NEWPAGE 0
SET LINESIZE 70
SPOOL OFF
If you do not want to see the output on your screen, you can also add SET TERMOUT
OFF to the beginning of the file and SET TERMOUT ON to the end of the file. Save
and close the file in your text editor (you will automatically return to SQL*Plus). Now,
run the script EMPRPT:
@EMPRPT
SQL*Plus displays the output on your screen (unless you set TERMOUT to OFF), and
spools it to the file TEMP:
6-28
7
Generating Reports from SQL*Plus
This chapter explains how to generate a HTML and CSV reports containing your query
results. This chapter covers the following topics:
• About Creating Reports using Command-line SQL*Plus
7-1
Chapter 7
About Creating Reports using Command-line SQL*Plus
In this example, the prompts and query text have not been suppressed. Depending on
how you invoke a script, you can use SET ECHO OFF or command-line -SILENT
options to do this.
The SQL*Plus commands in this example contain several items of usage worth noting:
• The hyphen used to continue lines in long SQL*Plus commands.
• The TABLE option to set table WIDTH and BORDER attributes.
• The COLUMN command to set ENTMAP OFF for the DEPARTMENT_NAME
column to enable the correct formation of HTML hyperlinks. This makes sure that
any HTML special characters such as quotes and angle brackets are not replaced
by their equivalent entities, ", &, < and >.
• The use of quotes and concatenation characters in the SELECT statement to
create hyperlinks by concatenating string and variable elements.
7-2
Chapter 7
About Creating Reports using Command-line SQL*Plus
View the report.html source in your web browser, or in a text editor to see that the
table cells for the Department column contain fully formed hyperlinks as shown:
<html>
<head>
<TITLE>Department Report</TITLE> <STYLE type="text/css">
<!-- BODY {background: #FFFFC6} --> </STYLE>
<meta name="generator" content="SQL*Plus 10.2.0.1">
</head>
<body TEXT="#FF00Ff">
SQL> SELECT '<A HREF="http://oracle.com/'
||DEPARTMENT_NAME||'.html">'||DEPARTMENT_NAME
||'</A>' DEPARTMENT_NAME, CITY
<br>
2 FROM EMP_DETAILS_VIEW
<br>
3* WHERE SALARY>12000
<br>
<p>
<table WIDTH="90%" BORDER="5">
<tr><th>DEPARTMENT</th><th>CITY</th></tr>
<tr><td><A HREF="http://oracle.com/Executive.html">Executive</A></td>
<td>Seattle</td></tr>
<tr><td><A HREF="http://oracle.com/Executive.html">Executive</A></td>
<td>Seattle</td></tr>
<tr><td><A HREF="http://oracle.com/Executive.html">Executive</A></td>
<td>Seattle</td></tr>
<tr><td><A HREF="http://oracle.com/Sales.html">Sales</A></td>
<td>Oxford</td></tr>
<tr><td><A HREF="http://oracle.com/Sales.html">Sales</A></td>
<td>Oxford</td></tr>
<tr><td><A HREF="http://oracle.com/Marketing.html">Marketing</A></td>
<td>Toronto</td></tr>
</table>
<p>
6 rows selected.<br>
The SQLPLUS command in this example contains three layers of nested quotes. From
the inside out, these are:
• "2" is a quoted HTML attribute value for BORDER.
7-3
Chapter 7
About Creating Reports using Command-line SQL*Plus
You use the COLUMN command to control column output. The following COLUMN
commands create new heading names for the SQL query output. The first command
also turns off entity mapping for the DEPARTMENT_NAME column to allow HTML
hyperlinks to be correctly created in this column of the output data:
COLUMN DEPARTMENT_NAME HEADING 'DEPARTMENT' ENTMAP OFF
COLUMN CITY HEADING 'CITY'
SET MARKUP HTML ON SPOOL ON enables SQL*Plus to write HTML to a spool file.
The following SPOOL command triggers the writing of the <HTML> and <BODY> tags
to the named file:
SPOOL report.html
The </BODY> and </HTML> tags are appended to the spool file, report.html, before it
is closed.
The output from report.sql is a file, report.html, that can be loaded into a web browser.
Open report.html in your web browser. It should appear something like the following:
Example 7-2 Creating a Report using the SQLPLUS Command
Enter the following command at the operating system prompt:
SQLPLUS -S -M "HTML ON TABLE 'BORDER="2"'" HR@Ora10g @depart.sql>depart.html
7-4
Chapter 7
About Creating Reports using Command-line SQL*Plus
This example starts SQL*Plus with user "HR", prompts for the HR password, sets
HTML ON, sets a BORDER attribute for TABLE, and runs the script depart.sql. The
output from depart.sql is a web page which, in this case, has been redirected to the file
depart.html using the ">" operating system redirect command (it may be different on
your operating system). It could be sent to a web browser if SQL*Plus was called in a
web server CGI script. See About Suppressing the Display of SQL*Plus Commands in
Reports for information about calling SQL*Plus from a CGI script.
Start your web browser and enter the appropriate URL to open depart.html:
The web browser displays the > character, but the actual text in the HTML encoded file
is the HTML entity, >. The SET MARKUP option, ENTMAP, controls the substitution
of HTML entities. ENTMAP is set ON by default. It ensures that the characters <, >, "
and & are always replaced by the HTML entities representing these characters. This
prevents web browsers from misinterpreting these characters when they occur in your
SQL*Plus commands, or in data resulting from your query.
You can set ENTMAP at a global level with SET MARKUP HTML ENTMAP ON, or at
a column level with COLUMN column_name ENTMAP ON.
7-5
Chapter 7
About Creating Reports using Command-line SQL*Plus
7-6
8
Tuning SQL*Plus
This chapter provides information about how to tune SQL*Plus for better performance.
It discusses the following topics:
• About Tracing Statements
• About Collecting Timing Statistics
• Tracing Parallel and Distributed Queries
• Execution Plan Output in Earlier Databases
• About SQL*Plus Script Tuning
For information about tuning Oracle Database, see the Oracle Database Performance
Tuning Guide.
To use this feature, you must create a PLAN_TABLE table in your schema and then
have the PLUSTRACE role granted to you. DBA privileges are required to grant the
PLUSTRACE role. For information on how to grant a role and how to create the
PLAN_TABLE table, see the Oracle Database SQL Language Reference.
8-1
Chapter 8
About Tracing Statements
For more information about the roles and the PLAN_TABLE, see the Oracle Database
SQL Language Reference and the AUTOTRACE variable of the SET command.
Note:
SQL*Plus AUTOTRACE does not support switching containers with the
ALTER SESSION SET CONTAINER option. Statistical data gathered in this
case may be inconsistent.
Table created.
Role dropped.
Role created.
Grant succeeded.
Grant succeeded.
8-2
Chapter 8
About Tracing Statements
8.1.3 Statistics
The statistics are recorded by the server when your statement executes and indicate
the system resources required to execute your statement. The results include the
following statistics.
The client referred to in the statistics is SQL*Plus. Oracle Net refers to the generic
process communication between SQL*Plus and the server, regardless of whether
Oracle Net is installed. You cannot change the default format of the statistics report.
For a more complete list of database statistics, see Statistics Descriptions. For more
information about the statistics and how to interpret them, see Gathering Database
Statistics.
LAST_NAME SALARY JOB_TITLE
------------------------- ---------- -----------------------------------
King 24000 President
De Haan 17000 Administration Vice President
Kochhar 17000 Administration Vice President
Partners 13500 Sales Manager
Russell 14000 Sales Manager
Hartstein 13000 Marketing Manager
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2988506077
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
8-3
Chapter 8
About Tracing Statements
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6 | 360 | 6 (17)| 00:00:01 |
|* 1 | HASH JOIN | | 6 | 360 | 6 (17)| 00:00:01 |
|* 2 | TABLE ACCESS FULL| EMPLOYEES| 6 | 204 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| JOBS | 19 | 494 | 2 (0)| 00:00:01 |
------------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
10 consistent gets
0 physical reads
0 redo size
706 bytes sent via Oracle Net Services to client
496 bytes received via Oracle Net Services from client
2 Oracle Net Services roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
6 rows processed
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2988506077
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6 | 360 | 6 (17)| 00:00:01 |
|* 1 | HASH JOIN | | 6 | 360 | 6 (17)| 00:00:01 |
|* 2 | TABLE ACCESS FULL| EMPLOYEES| 6 | 204 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| JOBS | 19 | 494 | 2 (0)| 00:00:01 |
------------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
10 consistent gets
0 physical reads
0 redo size
8-4
Chapter 8
About Collecting Timing Statistics
This option is useful when you are tuning a large query, but do not want to see the
query report.
Note:
Your output may vary depending on the server version and configuration.
8-5
Chapter 8
Tracing Parallel and Distributed Queries
Table created.
Index created.
Execution Plan
----------------------------------------------------------
Plan hash value: 107954098
-------------------------------------------------------------------------------------
-------------------------
| Id | Operation | Name | Rows |Bytes| Cost(%CPU)| Time |
TQ |IN-OUT| PQ Distrib |
-------------------------------------------------------------------------------------
-------------------------
| 0 | SELECT STATEMENT | | 1 | 26 | 1 (0)| 00:00:01
| | | |
| 1 | SORT AGGREGATE | | 1 | 26 | |
| | | |
| 2 | PX COORDINATOR | | | | |
| | | |
| 3 | PX SEND QC (RANDOM) | :TQ10001| 1 | 26 | | |
Q1,01 | P->S | QC (RAND) |
| 4 | SORT AGGREGATE | | 1 | 26 | | |
Q1,01 | PCWP | |
| 5 | NESTED LOOPS | | 1 | 26 | 1 (0)| 00:00:01 |
Q1,01 | PCWP | |
| 6 | PX RECEIVE | | | | | |
Q1,01 | PCWP | |
| 7 | PX SEND BROADCAST | :TQ10000| | | | |
Q1,00 | P->P | BROADCAST |
| 8 | PX BLOCK ITERATOR | | 1 | 13 | 0 (0)| 00:00:01 |
Q1,00 | PCWC | |
| 9 | TABLE ACCESS FULL| D2_T2 | 1 | 13 | 0 (0)| 00:00:01 |
Q1,00 | PCWP | |
| 10 | PX BLOCK ITERATOR | | 1 | 13 | 2 (0)| 00:00:01 |
Q1,01 | PCWC | |
|* 11 | TABLE ACCESS FULL | D2_T1 | 1 | 13 | 2 (0)| 00:00:01 |
Q1,01 | PCWP | |
-------------------------------------------------------------------------------------
-------------------------
Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
467 recursive calls
8-6
Chapter 8
Execution Plan Output in Earlier Databases
27 db block gets
147 consistent gets
20 physical reads
4548 redo size
502 bytes sent via Oracle Net Services to client
496 bytes received via Oracle Net Services from client
2 Oracle Net Services roundtrips to/from client
14 sorts (memory)
0 sorts (disk)
1 rows processed
If consistent gets or physical reads are high relative to the amount of data returned, it
indicates that the query is expensive and needs to be reviewed for optimization. For
example, if you are expecting less than 1,000 rows back and consistent gets is
1,000,000 and physical reads is 10,000, further optimization is needed.
Note:
You can also monitor disk reads and buffer gets using V$SQL or TKPROF.
The format of the columns may be altered with the COLUMN command. For example,
to stop the PARENT_ID_PLUS_EXP column being displayed, enter
COLUMN PARENT_ID_PLUS_EXP NOPRINT
8-7
Chapter 8
About SQL*Plus Script Tuning
The Execution Plan output is generated using the EXPLAIN PLAN command.
When you trace a statement in a parallel or distributed query, the Execution Plan
shows the cost based optimizer estimates of the number of rows (the cardinality). In
general, the cost, cardinality and bytes at each node represent cumulative results. For
example, the cost of a join node accounts for not only the cost of completing the join
operations, but also the entire costs of accessing the relations in that join.
Lines marked with an asterisk (*) denote a parallel or remote operation. Each
operation is explained in the second part of the report. See Distributed Transactions
Concepts for more information on parallel and distributed operations.
The second section of this report consists of three columns displayed in the following
order
The format of the columns may be altered with the COLUMN command.
8-8
Chapter 8
About SQL*Plus Script Tuning
8-9
Chapter 8
About SQL*Plus Script Tuning
8.5.14 UNDEFINE
Deletes substitution variables that you defined either explicitly (with the DEFINE
command) or implicitly (with an argument to the START command or COLUMN
NEW_VAL|OLD_VAL).
Use the UNDEFINE command to remove unnecessary substitution variables. This can
reduce the time taken for any operation that uses '&', new_value or old_value
variables.
8-10
9
SQL*Plus Security
This chapter describes the available methods for controlling access to database
tables, and SQL*Plus commands. It covers the following topics:
• About the PRODUCT_USER_PROFILE Table
• Disabling SQL*Plus_ SQL_ and PL/SQL Commands
• About Creating and Controlling Roles
• About Disabling Commands with SQLPLUS -RESTRICT
• About Program Argument Security
9-1
Chapter 9
About the PRODUCT_USER_PROFILE Table
Note:
If the table is created incorrectly, all users other than privileged users will see
a warning when connecting to Oracle Database that the PUP table information
is not loaded.
9-2
Chapter 9
Disabling SQL*Plus, SQL, and PL/SQL Commands
9-3
Chapter 9
Disabling SQL*Plus, SQL, and PL/SQL Commands
• STARTUP
• BREAK
• EDIT
• RECOVER
• STORE
• BTITLE
• EXECUTE
• REMARK
• TIMING
• CHANGE
• EXIT/QUIT
• REPFOOTER
• TTITLE
• CLEAR
• GET
• REPHEADER
• UNDEFINE
• COLUMN
• HELP (?)
• RUN
• VARIABLE
• COMPUTE
• HOST
• SAVE
• WHENEVER OSERROR
• CONNECT
• INPUT
• SET
• WHENEVER SQLERROR
• COPY
• LIST (;)
• SHOW
• XQUERY
SQL commands that can be disabled:
• ALTER
• ANALYZE
• ASSOCIATE
9-4
Chapter 9
Disabling SQL*Plus, SQL, and PL/SQL Commands
• AUDIT
• CALL
• COMMENT
• COMMIT
• CREATE
• DELETE
• DISASSOCIATE
• DROP
• EXPLAIN
• FLASHBACK
• GRANT
• INSERT
• LOCK
• MERGE
• NOAUDIT
• PURGE
• RENAME
• REVOKE
• ROLLBACK
• SAVEPOINT
• SELECT
• SET CONSTRAINTS
• SET ROLE
• SET TRANSACTION
• TRUNCATE
• UPDATE
• VALIDATE
You can disable the following PL/SQL commands:
• BEGIN
• DECLARE
9-5
Chapter 9
About Creating and Controlling Roles
Note:
• Disabling HOST disables the operating system alias for HOST, such as $
on Windows, and ! on UNIX.
• Disabling LIST disables ; and numbers (numbers entered to go to that line
in a script).
• You must disable HELP and ? separately to disable access to command-
line help.
• Disabling the SQL*Plus SET command also disables SQL SET
CONSTRAINTS, SET ROLE and SET TRANSACTION.
• Disabling SQL*Plus START also disables @ and @@.
• Disabling BEGIN and DECLARE does not prevent the use of SQL*Plus
EXECUTE to run PL/SQL. EXECUTE must be disabled separately.
• Disabling EXIT/QUIT is not recommended. If disabled, terminate a
command-line session by sending an EOF character such as Ctrl+D in
UNIX or Ctrl+Z in Windows. Otherwise, terminate a session by terminating
the SQL*Plus process. If disabled, the EXIT operation in WHENEVER
OSERROR and WHENEVER SQLERROR is also disabled.
9-6
Chapter 9
About Creating and Controlling Roles
• To grant access to roles, you use the GRANT command. In this way, you can
control who has access to the privileges associated with the role.
• To access roles, you use the SET ROLE command. If you created the role with a
password, the user must know the password in order to access the role.
Note:
When you enter "PUBLIC" or "%" for the Userid column, you disable the role
for all users. You should only use "%" or "PUBLIC" for roles which are granted
to "PUBLIC". If you try to disable a role that has not been granted to a user,
none of the roles for that user are disabled.
The Scope, Numeric_Value, and Date_Value columns should contain NULL. For
example:
PRODUCT USERID ATTRIBUTE SCOPE NUMERIC CHAR DATE LONG
VALUE VALUE VALUE VALUE
------- ------ --------- ----- -------- ------ ----- -----
SQL*Plus HR ROLES ROLE1
SQL*Plus PUBLIC ROLES ROLE2
During login, these table rows are translated into the command
SET ROLE ALL EXCEPT ROLE1, ROLE2
To ensure that the user does not use the SET ROLE command to change their roles
after login, you can disable the SET ROLE command.
To re-enable roles, delete the row containing the restriction.
See About Disabling SET ROLE for more information.
9-7
Chapter 9
About Disabling Commands with SQLPLUS -RESTRICT
Note:
• Disabling HOST also disables your operating system's alias for HOST,
such as $ on Windows, and ! on UNIX.
• Disabling the SQL*Plus START command will also disable the SQL*Plus
@ and @@ commands.
For more information about the RESTRICT option, see the SQLPLUS RESTRICT
Option.
9-8
Chapter 9
About Program Argument Security
• To run a batch SQL script, hard code the username and password as the first line
of the SQL script. Then call the script with:
sqlplus @myscript.sql
When SQL*Plus is started like this, it uses the first line of the script as the username/
password@connection_identifier string.
Avoid storing your username and password in files or scripts. If you do store your
username and password in a file or script, ensure that the file or script is secured from
non-authorized access.
ACCEPT HIDE option document here?
Update content to be consistent with security requirements
9-9
10
Database Administration with SQL*Plus
This chapter provides a brief overview of the database administration tools available in
SQL*Plus, and discusses the following topics:
• Overview
• Introduction to Database Startup and Shutdown
• Redo Log Files
• Database Recovery
This chapter is intended for use by database administrators. You must have database
administrator privileges to use this functionality.
For more information on database administration, see the Oracle Database Concepts
manual.
10.1 Overview
Special operations such as starting up or shutting down a database are performed by
a database administrator (DBA). The DBA has certain privileges that are not assigned
to normal users. The commands outlined in this chapter would normally be used by a
DBA.
For more information about security and roles in SQL*Plus, see SQL*Plus Security.
10-1
Chapter 10
Introduction to Database Startup and Shutdown
where SALES is the database name specified in the DB_NAME parameter in the
INITSALES.ORA parameter file.
For more information about database startup, see Starting Up and Shutting Down. For
more information about starting a database, see the STARTUP command.
For more information about database startup, see Starting Up and Shutting Down. For
more information about starting a database, see the STARTUP command.
10-2
Chapter 10
Redo Log Files
Shutting down an instance reclaims the SGA from memory and terminates the
background Oracle Database processes that constitute an Oracle Database
instance.
Example 10-4 Shutting Down the Database
To shut down the database normally after it has been opened and mounted, enter
SHUTDOWN
For more information about database shutdown, see Shutting Down a Database. For
information about stopping a database, see the SHUTDOWN command.
Database closed.
Database dismounted.
ORACLE instance shut down.
Note:
• When the current container is a PDB, the SHUTDOWN command only closes
the PDB, not the CDB instance.
• There is no SHUTDOWN command for a PDB that is equivalent to SHUTDOWN
TRANSACTIONAL or SHUTDOWN ABORT for a non-CDB.
For more information about database startup, see the Oracle Database Administrator's
Guide guide. For more information about starting a database, see the STARTUP
command.
10-3
Chapter 10
Database Recovery
The SQL ALTER SYSTEM command enables a complete recovery from disk failure as
well as instance failure, because all changes made to the database are permanently
saved in an archived redo log.
For more information about redo log files and database archiving modes, see the
ARCHIVE LOG command.
To list the details of the current log file being archived, enter
ARCHIVE LOG LIST
Make sure that the tablespaces you are interested in recovering have been taken
offline, before proceeding with recovery for those tablespaces.
10-4
11
SQL*Plus Globalization Support
Globalization support enables the storing, processing and retrieval of data in native
languages. The languages that can be stored in an Oracle database are encoded by
Oracle Database-supported character sets. Globalization support ensures that
database utilities, error messages, sort order, and date, time, monetary, numeric, and
calendar conventions adjust to the native language and locale.
Topics:
• About Configuring Globalization Support in Command-line SQL*Plus
• NLS_LANG Environment Variable
For more information on globalization support, see the Oracle Technology Network
globalization notes at http://www.oracle.com/technetwork/products/globalization/
11-1
Chapter 11
Setting NLS_LANG
Setting up locale specific behavior on the SQL*Plus client is achieved with the use of
NLS parameters. These parameters may be specified in a number of ways, including
as an initialization parameter on the server. For settings that control the behavior of
the server, see NLS Database Parameters.
NLS_LANG has the syntax:
NLS_LANG = language_territory.charset
where language specifies the conventions to use for Oracle Database messages,
sorting order, day and month names. For example, to receive messages in Japanese,
set language to JAPANESE. If language is not set, it defaults to AMERICAN.
where territory specifies the convention for default dates, and for monetary, and
numeric formats. For example to use the Japanese territory format, set territory to
JAPAN. If territory is not set, the default value is derived from the language value, and
so is set to AMERICA.
where, in SQL*Plus command-line, charset specifies the character set encoding used
by SQL*Plus for data processing, and is generally suited to that of the users terminal.
Illogical combinations can be set, but will not work. For example, Japanese cannot be
supported using a Western European character set such as:
NLS_LANG=JAPANESE_JAPAN.WE8DEC
However, Japanese could be supported with the Unicode character set. For example:
NLS_LANG=JAPANESE_JAPAN.UTF8
11-2
Chapter 11
Setting NLS_LANG
or
setenv NLS_LANG Japanese_Japan.JA16SJIS
or
setenv NLS_LANG Japanese_Japan.JA16EUC
The locale setting of your UNIX terminal determines the exact value of the
NLS_LANG parameter. For more information on the NLS_LANG setting, see
Specifying the Value of NLS_LANG.
Example 11-3 Configuring Japanese Support in Oracle Database
To store data in the Japanese character set using UTF-8 character encoding, ensure
that the Oracle database has been created with the AL32UTF8 character set. See
your Oracle Database Installation Guide for information about creating your database
in a character set other than US7ASCII.
11-3
Part III
SQL*Plus Reference
Part III contains the SQL*Plus command reference, and the list of SQL*Plus error
messages.
Part III contains the following chapters:
• SQL*Plus Command Reference
• SQL*Plus Error Messages
12
SQL*Plus Command Reference
This chapter contains descriptions of the SQL*Plus commands listed alphabetically.
Each description contains the following parts:
Section Description
Syntax Shows how to enter the command and provides a brief description
of the basic uses of the command.
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.
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 press Return. If you wish, however, you can enter a
semicolon at the end of a SQL*Plus command.
Adds specified text to the end of the current line in the buffer.
APPEND
12-1
Chapter 12
SQL*Plus Command Summary
Command Description
Places and formats a specified title at the bottom of each report
BTITLE
page, or lists the current BTITLE definition.
Lists the column definitions for the specified table, view, or synonym
DESCRIBE
or the specifications for the specified function procedure.
Commits pending changes to the database and logs the current user
DISCONNECT
off Oracle Database, but does not exit SQL*Plus.
Adds one or more new lines after the current line in the buffer.
INPUT
12-2
Chapter 12
SQL*Plus Command Summary
Command Description
Displays the specified text, then waits for the user to press Return.
PAUSE
Lists and runs the SQL command or PL/SQL block currently stored
RUN
in the SQL buffer.
Runs the SQL statements in the specified script. The script can be
START
called from a local file system or a web server in SQL*Plus
command-line.
Starts an Oracle Database instance and optionally mounts and
STARTUP
opens a database.
Records timing data for an elapsed period of time, lists the current
TIMING
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
TTITLE
lists the current TTITLE definition.
12-3
Chapter 12
@ (at sign)
Command Description
Declares a bind variable that can be referenced in PL/SQL, or lists
VARIABLE
the current display characteristics for a single variable or all
variables.
Exits SQL*Plus if an operating system command generates an error.
WHENEVER OSERROR
Runs the SQL*Plus statements in the specified script. The script can be called from
the local file system or from a web server. 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 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, SQL*Plus searches for a file with that filename and
extension in the current default directory. If SQL*Plus does not find the file in the
current directory, it searches a system-dependent path to find it. 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.
12-4
Chapter 12
@@ (double at sign)
Usage
All previous settings like COLUMN command settings stay in effect when the script
starts. If the script changes any setting, 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, SQL*Plus commands, or PL/SQL blocks).
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 SET SQLT[ERMINATOR] {; | c | ON | OFF} for more
information.
Examples
To run a script named PRINTRPT with the extension SQL, enter
@PRINTRPT
You can run a script named YEAREND specified by a URL, and pass values to
variables referenced in YEAREND in the usual way:
@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 with:
@HTTP://machine_name.domain:port/SCRIPTSERVER?ENDOFYEAR VAL1 VAL2
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.
12-5
Chapter 12
@@ (double at sign)
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 @
12-6
Chapter 12
/ (slash)
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.
12.4 / (slash)
Syntax
/(slash)
Executes the most recently executed SQL command or PL/SQL block which is 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.
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:
SELECT CITY, COUNTRY_NAMEFROM EMP_DETAILS_VIEWWHERE SALARY=12000;
CITY COUNTRY_NAME
------------------------------ ----------------------------------------
Seattle United States of America
Oxford United Kingdom
Seattle United States of America
12.5 ACCEPT
Syntax
ACC[EPT] variable [NUM[BER] | CHAR | DATE | BINARY_FLOAT | BINARY_DOUBLE] [FOR[MAT]
format] [DEF[AULT] default] [PROMPT text|NOPR[OMPT]] [HIDE]
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.
12-7
Chapter 12
ACCEPT
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
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. SeeFormat Models 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]
12-8
Chapter 12
APPEND
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: '
12.6 APPEND
Syntax
A[PPEND] text
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:
1
1* SELECT DEPARTMENT_ID
12-9
Chapter 12
ARCHIVE LOG
SQL*Plus appends the first semicolon to the line and interprets the second as the
terminator for the APPEND command.
Terms
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
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.
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.
12-10
Chapter 12
ATTRIBUTE
Note:
ARCHIVE LOG LIST only applies to the current instance. To START and
STOP archiving, use the SQL command ALTER SYSTEM. For more
information about using SQL commands, see the Oracle Database SQL
Language Reference.
12.8 ATTRIBUTE
Syntax
ATTR[IBUTE] [type_name.attribute_name [option ...]]
Specifies display characteristics for a given attribute of an Object Type column, such
as the format of NUMBER data. Columns and attributes should not have the same
names as they share a common namespace.
Also lists the current display characteristics for a single attribute or all attributes.
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.
Terms
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 applies to all such objects you reference in that session.
ALI[AS] alias
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.
12-11
Chapter 12
BREAK
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 twenty
characters wide, enter
ATTRIBUTE EMPLOYEE_TYPE.LAST_NAME FORMAT A20
12.9 BREAK
Syntax
BRE[AK] [ON report_element [action [action]]] ...
12-12
Chapter 12
BREAK
Terms
ON column [action [action]]
When you include actions, specifies actions 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 actions, 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 breaks,
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 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.
12-13
Chapter 12
BREAK
In BREAK commands, nulls are considered equal to each other, but not equal to
anything else. This is different to the treatment of nulls in WHERE clauses.
ON expr [action [action]]
When you include actions, specifies actions for SQL*Plus to take when the value of
the expression changes.
When you omit actions, BREAK ON expr suppresses printing of duplicate values of
expr and marks 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 for ON column also applies to ON expr.
ON ROW [action [action]]
When you include actions, specifies actions 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.
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 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 with 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.
12-14
Chapter 12
BREAK
DUP[LICATES]
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 additionally prints the sum of SALARY, you could enter the following commands.
(The example selects departments 50 and 80 and the jobs of clerk and salesman
only.)
BREAK ON DEPARTMENT_ID ON JOB_ID 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;
************* ----------
sum 64300
12-15
Chapter 12
BTITLE
************* ----------
sum 61000
25 rows selected.
12.10 BTITLE
Syntax
BTI[TLE] [printspec [text | variable] ...] | [ON | OFF]
where printspec represents one or more of the following clauses used to place and
format the text:
BOLD
CE[NTER]
COL n
FORMAT text
LE[FT]
R[IGHT]
S[KIP] [n]
TAB n
Places and formats a specified title at the bottom of each report page, or lists the
current BTITLE definition.
Enter BTITLE with no clauses to list the current BTITLE definition. For a description of
the old form of BTITLE, see BTI[TLE] text (obsolete old form).
Terms
See the TTITLE command for information on terms and clauses in the BTITLE
command syntax.
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.
SQL*Plus substitution variables (& variables) are expanded before BTITLE is
executed. The resulting string is stored as the BTITLE text. During subsequent
execution for each page of results, the expanded value of a variable may itself be
interpreted as a variable with unexpected results.
You can avoid this double substitution in a BTITLE command by not using the & prefix
for variables that are to be substituted on each page of results. If you want to use a
substitution variable to insert unchanging text in a BTITLE, enclose it in quotes so that
it is only substituted once.
12-16
Chapter 12
CHANGE
Examples
To set a bottom title with CORPORATE PLANNING DEPARTMENT on the left and a
date on the right, enter
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
BTITLE COL 50 'CONFIDENTIAL'
TAB 6
'1 JAN 2001'
12.11 CHANGE
Syntax
C[HANGE] sepchar old [sepchar [new [sepchar]]]
Changes the first occurrence of the specified text on the current line in the buffer.
Terms
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
finds the first occurrence of "aq", "AQ", "aQ", or "Aq" and changes 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.
12-17
Chapter 12
CHANGE
You can also use CHANGE to modify a line in the buffer that has generated an Oracle
Database 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:
3
You can replace the contents of an entire line using the line number. This entry
3 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,
2 CHANGE/OLD/NEW/
12-18
Chapter 12
CLEAR
12.12 CLEAR
Syntax
CL[EAR] option ...
Resets or erases the current value or setting for the specified option.
Terms
BRE[AKS]
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]
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]
Examples
To clear breaks, enter
CLEAR BREAKS
12-19
Chapter 12
COLUMN
12.13 COLUMN
Syntax
COL[UMN] [{column | expr} [option ...]]
Terms
{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]
12-20
Chapter 12
COLUMN
To reset the attributes for all columns, use the CLEAR COLUMNS command. CLEAR
COLUMNS also clears the ATTRIBUTEs for that column.
ENTMAP {ON | OFF}
Enables entity mapping to be turned on or off for selected columns in HTML output.
This feature enables 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, <, >, " and &, 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.
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_A[FTER] does not work in SET MARKUP HTML ON mode unless
PREFORMAT is set ON.
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. FOLD_A[FTER] does not work in SET MARKUP HTML ON mode
unless PREFORMAT is set ON.
FOR[MAT] format
Specifies the display format of the column. The format specification must be a text
constant such as A10 or $9,999.
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, BLOB, BFILE, 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 alphabetic.) If
you specify a width shorter than the column heading, SQL*Plus truncates the heading.
SQL*Plus truncates or wraps XMLType columns after 2000 bytes. To avoid this you
need to set an explicit COLUMN format for the XMLType column. A COLUMN format
can be up to a maximum of 60000 per row.
DATE Columns
12-21
Chapter 12
COLUMN
The default width and format of unformatted DATE columns in SQL*Plus is derived
from the NLS_DATE_FORMAT parameter. The NLS_DATE_FORMAT setting is
determined by the NLS territory parameter. For example, the default format for the
NLS territory, America, is DD-Mon-RR, and the default width is A9. The NLS
parameters may be set in your database parameter file, in environment variables or an
equivalent platform-specific mechanism. They may also be specified for each session
with the ALTER SESSION command. For more information about DATE formats, and
about NLS parameters, see the Oracle Database SQL Language Reference.
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 Database automatically enables
a very wide column. The default column width may also depend on the character sets
in use in SQL*Plus and in the database. To maximize script portability if multiple
characters sets are used, Oracle Database recommends using COLUMN FORMAT for
each column selected.
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
For numeric columns, COLUMN FORMAT settings take precedence over SET
NUMFORMAT settings, which take precedence over SET NUMWIDTH settings.
See SET NUMF[ORMAT] format and SET NUM[WIDTH] {10 | n}.
To change a NUMBER column's width, use FORMAT followed by an element as
specified in Table 12-1.
12-22
Chapter 12
COLUMN
EEEE Displays value in scientific notation (format must contain exactly four
9.999EEEE
"E"s).
G Displays the group separator in the specified positions in the integral
9G999
part of a number.
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 COLUMN FORMAT or SET
NUMFORMAT, then the column's width will always be at least the value of SET
NUMWIDTH.
12-23
Chapter 12
COLUMN
SQL*Plus may round your NUMBER data to fit your format or field width.
If a value cannot fit in the column, SQL*Plus displays pound signs (#) instead of the
number.
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'
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. NEWL[INE] does not work in SET MARKUP HTML ON mode
unless PREFORMAT is SET ON.
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.
Variables specified with NEW_V[ALUE] are expanded before TTITLE is executed. The
resulting string is stored as the TTITLE text. During subsequent execution for each
page of the report, the expanded value of a variable may itself be interpreted as a
variable with unexpected results.
You can avoid this double substitution in a TTITLE command by not using the & prefix
for NEW_V[ALUE] variables that are to be substituted on each page of the report. If
12-24
Chapter 12
COLUMN
you want to use a substitution variable to insert unchanging text in a TTITLE, enclose
it in quotes so that it is only substituted once.
For information on displaying a column value in the bottom title, see OLD_V[ALUE]
variable below. For more information on referencing variables in titles, see the TTITLE
command. For information on formatting and valid format models, see FOR[MAT]
format above.
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 always becomes 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.
Variables specified with OLD_V[ALUE] are expanded before BTITLE is executed. The
resulting string is stored as the BTITLE text. During subsequent execution for each
page of the report, the expanded value of a variable may itself be interpreted as a
variable with unexpected results.
You can avoid this double substitution in a BTITLE command by not using the & prefix
for OLD_V[ALUE] variables that are to be substituted on each page of the report. If
you want to use a substitution variable to insert unchanging text in a BTITLE, enclose
it in quotes so that it is only substituted once.
For information on displaying a column value in the top title, see NEW_V[ALUE]
variable. For more information on referencing variables in titles, see the TTITLE
command.
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
12-25
Chapter 12
COLUMN
boundary is not skipped. TRUNCATED truncates the string at the end of the first line
of display.
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.
Usage
The COLUMN commands you enter can control a column's display attributes for
multiple SQL SELECT commands.
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.
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
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
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
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
COLUMN REMARKS FORMAT A20 WRAP
12-26
Chapter 12
COMPUTE
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 instead of EMP_DETAILS_VIEW.
For details on creating a date variable, see About Displaying the Current Date in Titles.
Your two page report would look similar to the following report, with "Job Report"
centered within your current linesize:
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;
To change the default format of DATE columns to 'YYYY-MM-DD', you can enter
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD';
Session altered.
Job: SA_MAN
HIRE_DATE
----------
1994-06-07
12.14 COMPUTE
Syntax
COMP[UTE] [function [LAB[EL] text] ... OF {expr | column | alias} ... ON
{expr | column | alias | REPORT | ROW} ...]
In combination with the BREAK command, 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 About Clarifying Your
Report with Spacing and Summary Lines.
12-27
Chapter 12
COMPUTE
Terms
function ...
Represents one of the functions listed in Table 12-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.
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
12-28
Chapter 12
COMPUTE
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} ...
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:
• One or more of the expressions, columns, or column aliases you reference in the
OF clause must also be in the SELECT command.
• The expression, column, or column alias you reference in the ON clause must
occur in the SELECT command and in the most recent BREAK command.
• If you reference either ROW or REPORT in the ON clause, also reference ROW or
REPORT in the most recent BREAK command.
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
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;
12-29
Chapter 12
COMPUTE
6 rows selected.
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
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;
To sum salaries for departments <= 20 without printing the compute label, enter
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;
12-30
Chapter 12
CONNECT
20 Hartstein 13000
20 Fay 6000
----------
19000
To total the salary at the end of the report without printing the compute label, enter
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;
9 rows selected.
12.15 CONNECT
Syntax
CONN[ECT] [{logon | / | proxy} [AS {SYSASM |SYSBACKUP |SYSDBA |SYSDG |SYSOPER |
SYSRAC | SYSKM}] [edition=value]]
12-31
Chapter 12
CONNECT
Note:
The brackets around username in proxy are required syntax, not an indication
of an optional term. For example, to connect to scott through proxy user hr
with password welcome1.
CONNECT hr[scott]/welcome1
Connects a given username to the Oracle Database. When you run a CONNECT
command, the site profile, glogin.sql, and the user profile, login.sql, are executed.
CONNECT does not reprompt for username or password if the initial connection does
not succeed.
WARNING:
Including your password in plain text is a security risk. You can avoid this risk
by omitting the password, and entering it only when the system prompts for it.
To connect to a database using an enterprise user proxy, you must first configure the
proxy. For information about configuring an enterprise user proxy, see the Oracle
Database Enterprise User Security Administrator's Guide.
Terms
username[/password]
The username and password you use to connect to Oracle Database. If you omit
username and password, SQL*Plus prompts you for them. If you enter a slash (/) or
enter Return or click Execute when prompted for username, SQL*Plus logs you in
using a default logon. See / (slash) for more information.
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.
connect_identifier
An Oracle Net connect identifier. The exact syntax depends on the Oracle Net
configuration. For more information, refer to the Oracle Net manual 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.
A connect_identifier is also used to connect to a pluggable database (PDB). See
Oracle Database Administrator's Guide
edition=value
The value for the Oracle Session Edition. An edition enables two or more versions of
an object in a database. It provides a staging area where changed objects can be
loaded into the database, compiled, and executed during uptime. This is particularly
12-32
Chapter 12
CONNECT
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 Oracle Database Administrator's Guide for information
about operating system authentication.
In SQL*Plus command line, where applications use password credentials to connect to
databases, it is possible to store the credentials in a client-side Oracle wallet. When
you configure a client to use the Oracle wallet, applications can use the following
syntax to connect to databases that use password authentication:
CONNECT /@database_alias
For information about configuring your client to use secure external password store
and for information about managing credentials in it, see the Oracle Database Security
Guide.
AS {SYSASM |SYSBACKUP |SYSDBA |SYSDG |SYSOPER |SYSRAC |SYSKM}
The AS clause enables privileged connections by users who have been granted that
system privileges. You can use any one of these privileged connections with the
default logon, /.
For information about system privileges, see the Oracle Database Administrator's
Guide.
Usage
CONNECT commits the current transaction to the database, disconnects the current
username from Oracle Database, 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 Oracle Database SQL
Language Reference.
Examples
To connect across Oracle Net with username HR, to the database known by the
Oracle Net alias as FLEETDB, enter
CONNECT HR@FLEETDB
For more information about setting up your password file, refer to the Oracle Database
Administrator's Guide.
To connect to an instance on the current node as a privileged user named HR, enter
CONNECT HR AS SYSDBA
12-33
Chapter 12
COPY
You can use the CONNECT command to connect to a CDB or a non CDB using easy
connect or a net service name.
This statement connects to the hr user using the hrapp service. The hrapp service
has a PDB property for the hrpdb PDB. This example assumes that the client is
configured to have a Net Service Name for the hrapp service.
CONNECT hr@hrapp
12.16 COPY
The COPY command is not being enhanced to handle datatypes or features
introduced with, or after Oracle8i. The COPY command is likely to be deprecated in a
future release.
For COPY command details and syntax, see SQL*Plus COPY Command.
12.17 DEFINE
Syntax
DEF[INE] [variable] | [variable = text]
Specifies a user or predefined variable and assigns a CHAR value to it, or lists the
value and variable type of a single variable or all variables.
Terms
variable
Represents the user or predefined 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
Usage
Defined variables retain their values until you:
• enter a new DEFINE command referencing the variable
• enter an UNDEFINE command referencing the variable
• enter an ACCEPT command referencing the variable
• reference the variable in the NEW_VALUE or OLD_VALUE clause of a COLUMN
command and then reference the column in a SELECT command
12-34
Chapter 12
DEFINE
• EXIT SQL*Plus
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.
If the value of a defined variable extends over multiple lines (using the SQL*Plus
command continuation character), SQL*Plus replaces each continuation character and
carriage return with a space. 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:
DEFINE POS = MANAGER
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
DEFINE DEPARTMENT_ID
12-35
Chapter 12
DEFINE
_CONNECT_IDENTIFIER
Contains the INSTANCE_NAME, SERVICE_NAME or ORACLE_SID from the connection identifier.
If a connection identifier is not supplied by the user during connection, the
_CONNECT_IDENTIFIER contains the ORACLE_SID.
_DATE
Contains either the current date as a dynamic variable, or a fixed string. The current
date is the default and is formatted using the value of NLS_DATE_FORMAT.
Because _DATE can be used as a normal substitution variable, users may put it in
TTITLE. If _DATE is dynamic and is used in TTITLE it will have all the normal variable
semantics. If it is used with an ampersand than the value will be set to the time when
the TTITLE command is executed. If it is used without an ampersand prefix, it will be
re-evaluated for each page. For long reports with _DATE in the TTITLE or with
multiple references to &_DATE, different times may be displayed for each occurrence
of the variable.
Users using _DATE in TTITLEs will almost certainly want to use an ampersand:
&_DATE, so that each page of the report has exactly the same timestamp. This is
especially true when the current date format contains a "seconds" component.
A DEFINE (with no arguments) or dereference using &_DATE will give the current
date.
The _DATE value can be UNDEFINED, or set to a fixed string with an explicit DEFINE
_DATE.
You can re-enable the default dynamic date behavior with:
DEFINE _DATE = "" (an empty string)
_EDITOR
Specifies the default editor used by the EDIT command.
During SQL*Plus installation on Windows operating systems, it is set to Notepad. On
UNIX operating systems, it is set to the value of the UNIX environment variable,
EDITOR, if it exists, otherwise it is set to Ed.
12-36
Chapter 12
DEFINE
You can use the DEFINE command to redefine _EDITOR, to hold the name of your
preferred text editor. For example, to define the editor used by EDIT to be vi, enter the
following command:
DEFINE _EDITOR = vi
_O_VERSION
Contains the current version of the installed Oracle Database in the form:
Oracle Database 12c Release 12.2.0.0.0 - Beta
_O_RELEASE
Contains the full release number of the installed Oracle Database in the form:
1201000100
_PRIVILEGE
Contains a value indicating the privilege level of the current connection. It contains one
of the following values:
• AS SYSASM
• AS SYSBACKUP
• AS SYSDBA
• AS SYSDG
• AS SYSOPER
• AS SYSRAC
• An empty string for normal-user connections or when there is no connection.
AS SYSASM, AS SYSBACKUP, AS SYSDBA, AS SYSDG, AS SYSOPER and AS
SYSRAC are database administrator level privileges.
See Also:
GRANT for information on AS SYSDBA and AS SYSOPER privileges.
_SQLPLUS_RELEASE
Contains the full release number of the installed SQL*Plus component in the form:
1201000100
_USER
Contains the user name connected to the current connection.
You can view the value of each of these variables with the DEFINE command.
These variables can be accessed and redefined like any other substitution variable.
They can be used in TTITLE, in '&' substitution variables, or in your SQL*Plus
command-line prompt.
12-37
Chapter 12
DEL
You can use the DEFINE command to view the definitions of these nine predefined
variables in the same way as you view other DEFINE definitions. You can also use the
DEFINE command to redefine their values, or you can use the UNDEFINE command
to remove their definitions and make them unavailable.
To view a specific variable definition, enter
DEFINE variable
where variable is the name of the substitution variable whose definition you want to
view.
To view all predefined and user defined variable definitions, enter
DEFINE
All predefined and all user defined variable definitions are displayed.
You can use UNDEFINE to remove a substitution variable definition and make it
unavailable.
12.18 DEL
Syntax
DEL [n | n m | n * | n LAST | * | * n | * LAST | LAST]
Terms
Term Description
Deletes line n.
n
12-38
Chapter 12
DEL
Term Description
Deletes the current line through line n.
* n
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 DELETE.
Examples
Assume the SQL buffer contains the following query:
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
LIST 3
followed by
DEL
12-39
Chapter 12
DESCRIBE
12.19 DESCRIBE
Syntax
DESC[RIBE] {[schema.]object[@db_link]}
Lists the column definitions for the specified table, view or synonym, or the
specifications for the specified function or procedure.
Terms
schema
Represents the schema where the object or permission to describe the object resides.
If you omit schema and the object is not a public synonym, SQL*Plus assumes you
own object.
object
Represents the table, view, type, procedure, function, package or synonym you wish
to describe.
@db_link
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 Oracle Database SQL Language Reference.
Usage
The description for tables, views, types and synonyms contains the following
information:
• each column's name
• whether or not null values are allowed (NULL or NOT NULL) for each column
• datatype of columns, for example, CHAR, DATE, LONG, LONGRAW, NUMBER,
RAW, ROWID, VARCHAR2 (VARCHAR), or XMLType
• precision of columns (and scale, if any, for a numeric column)
When you do a DESCRIBE, VARCHAR columns are returned with a type of
VARCHAR2.
The DESCRIBE command enables 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.
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.
The description for functions and procedures contains the following information:
12-40
Chapter 12
DESCRIBE
Examples
To describe the view EMP_DETAILS_VIEW, enter
DESCRIBE EMP_DETAILS_VIEW
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
CREATE PACKAGE apack AS
PROCEDURE aproc(P1 CHAR, P2 NUMBER);
PROCEDURE bproc(P1 CHAR, P2 NUMBER);
END apack;
/
Package created.
DESCRIBE apack
PROCEDURE APROC
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
P1 CHAR IN
P2 NUMBER IN
12-41
Chapter 12
DESCRIBE
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
CREATE TYPE ADDRESS AS OBJECT
( STREET VARCHAR2(20),
CITY VARCHAR2(20)
);
/
Type created.
DESCRIBE address
To create and describe the object type EMPLOYEE that contains the attributes
LAST_NAME, EMPADDR, JOB_ID and SALARY, enter
CREATE TYPE EMPLOYEE AS OBJECT
(LAST_NAME VARCHAR2(30),
EMPADDR ADDRESS,
JOB_ID VARCHAR2(20),
SALARY NUMBER(7,2)
);
/
Type created.
DESCRIBE employee
To create and describe the object type addr_type as a table of the object type
ADDRESS, enter
CREATE TYPE addr_type IS TABLE OF ADDRESS;
/
Type created.
DESCRIBE addr_type
12-42
Chapter 12
DESCRIBE
To create and describe the object type addr_varray as a varray of the object type
ADDRESS, enter
CREATE TYPE addr_varray AS VARRAY(10) OF ADDRESS;
/
Type created.
DESCRIBE addr_varray
To create and describe the table department that contains the columns
DEPARTMENT_ID, PERSON and LOC, enter
CREATE TABLE department
(DEPARTMENT_ID NUMBER,
PERSON EMPLOYEE,
LOC NUMBER
);
/
Table created.
DESCRIBE department
To create and describe the object type rational that contains the attributes
NUMERATOR and DENOMINATOR, and the METHOD rational_order, enter
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) );
/
12-43
Chapter 12
DESCRIBE
DENOMINATOR NUMBER
METHOD
------
MAP MEMBER FUNCTION RATIONAL_ORDER RETURNS NUMBER
To create a table which contains a column of XMLType, and describe it, enter
CREATE TABLE PROPERTY (Price NUMBER, Description SYS.XMLTYPE);
Table created
DESCRIBE PROPERTY;
To display the settings for the object, use the SHOW command as follows:
SHOW DESCRIBE
DESCRIBE employee
To create and describe the table des2_table which contains an encrypted column col2,
enter
CREATE TABLE des2_table (
col1 VARCHAR2(10),
col2 VARCHAR2(15) ENCRYPT,
col3 CHAR(5),
col4 CHAR(20));
Table created
DESCRIBE des2_table;
12-44
Chapter 12
DISCONNECT
For more information on using the CREATE TYPE command, see your Oracle
Database SQL Language Reference.
For information about using the SET DESCRIBE and SHOW DESCRIBE commands,
see the SET and SHOW commands.
12.20 DISCONNECT
Syntax
DISC[ONNECT]
Commits pending changes to the database and logs the current username out of
Oracle Database, 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 Database but have the user remain in SQL*Plus. In
SQL*Plus command-line, use EXIT or QUIT to log out of Oracle Database and return
control to your computer's operating system.
Examples
Your script might begin with a CONNECT command and end with a DISCONNECT, as
shown later.
CONNECT HR
SELECT LAST_NAME, DEPARTMENT_NAME FROM EMP_DETAILS_VIEW;
DISCONNECT
SET INSTANCE FIN2
CONNECT HR2
12.21 EDIT
Syntax
ED[IT] [file_name[.ext]]
where file_name[.ext] represents the file you wish to edit (typically a script).
Invokes an operating system text editor on the contents of the specified file or on the
contents of the buffer.
Enter EDIT with no filename to edit the contents of the SQL buffer with the 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.
If you specify a filename, SQL*Plus searches for the file in the directory set by
ORACLE_PATH. If SQL*Plus cannot find the file in ORACLE_PATH, or if
ORACLE_PATH is not set, it searches for the file in the current working directory. If
12-45
Chapter 12
EXECUTE
SQL*Plus cannot find the file in either directory, it creates a file with the specified
name.
The substitution variable, _EDITOR, contains the name of the text editor invoked by
EDIT. You can change the text editor by changing the value of _EDITOR. For
information about changing the value of a substitution variable, see DEFINE. EDIT
attempts to run the default operating system editor if _EDITOR is undefined.
EDIT places the contents of the SQL buffer in a file named AFIEDT.BUF by default (in
your current working directory) and runs 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.
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.
In SQL*Plus 9.0 and earlier versions on Windows, the command EDIT * opened a
blank file after giving an invalid filename warning. In SQL*Plus 10 and later versions
on Windows, EDIT * gives an invalid filename warning and does not open a blank file.
To retain the SQL*Plus 9.0 behavior, enter the set command,
SET SQLPLUSCOMPATIBILITY 9.0
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.
Note:
In Windows, if you use WordPad as your editor (_EDITOR=write.exe), the
buffer is not reloaded when you exit WordPad. In this case, use GET to reload
the buffer.
Examples
To edit the file REPORT with the extension SQL using your operating system text
editor, enter
EDIT REPORT
12.22 EXECUTE
Syntax
EXEC[UTE] statement
12-46
Chapter 12
EXIT
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.
You can suppress printing of the message "PL/SQL procedure successfully
completed" with SET FEEDBACK OFF.
Examples
If the variable :n has been defined with:
VARIABLE n NUMBER
For information on how to create a bind variable, see the VARIABLE command.
12.23 EXIT
Syntax
{EXIT | QUIT} [SUCCESS | FAILURE | WARNING | n | variable | :BindVariable] [COMMIT |
ROLLBACK]
Commits or rolls back all pending changes, logs out of Oracle Database, terminates
SQL*Plus and returns control to the operating system.
Terms
{EXIT | QUIT}
Exits normally.
FAILURE
12-47
Chapter 12
GET
COMMIT
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
Usage
EXIT enables you to specify an operating system return code. This enables 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.
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.
Examples
The following example commits all uncommitted transactions and returns the error
code of the last executed SQL command or PL/SQL block:
EXIT SQL.SQLCODE
12.24 GET
Syntax
GET [FILE] file_name[.ext] [LIST | NOLIST]
12-48
Chapter 12
HELP
Terms
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]
Lists the contents of the file after it is loaded. This is the default.
NOLIST
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 SET
SUF[FIX] {SQL | text}.
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
SAVE for more information.
Examples
To load a file called YEARENDRPT with the extension SQL into the buffer, enter
GET YEARENDRPT
12.25 HELP
Syntax
HELP | ? [topic]
12-49
Chapter 12
HISTORY
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
HELP INDEX
or
? INDEX
To see a single column list of SQL*Plus commands for which help is available, enter
HELP TOPICS
12.26 HISTORY
Syntax
HIST[ORY] [n RUN | EDIT | DEL[ETE]] | [CLEAR | LIST]
Enables users to run, edit, or delete previously used SQL*Plus, SQL, or PL/SQL
commands from the history list in the current session. You can enable or disable the
HISTORY command in the current SQL*Plus session by using the SET HISTORY
command.
The HISTORY command enables you to:
• List all entries in the command history list.
• Run an entry in the command history list.
• Edit an entry in the command history list.
• Delete an entry from the command history list.
• Clear all entries in the command history list.
Terms
HIST[ORY]
12-50
Chapter 12
HISTORY
Represents an entry in the command history list. An asterisk (*) indicates the last used
command in the command history list.
RUN
EDIT
Enables you to edit entry n in the command history list, using the default text editor.
After you edit entry n in the command history list and save the changes, a new entry is
created at the end of the list. When the number of entries in the command history list
reaches the maximum limit, the oldest entry in the list will be cleared to accommodate
the new entry.
DEL[ETE]
Enables you to delete entry n from the command history list. After you delete an entry
from the history list, the list is reordered to reflect the most recent changes.
CLEAR
Enables you to clear all entries in the history list. Once cleared, the history list cannot
be recovered.
LIST
Lists all entries in the history list. This is the same as using the HIST[ORY] command
by itself.
Usage
You can use the SQL*Plus DEFINE command to define the variable, _EDITOR, to
hold the name of your preferred text editor. For example, to define the editor used by
EDIT to be vi, enter the following command:
DEFINE _EDITOR = vi
EDIT attempts to run the default operating system editor if _EDITOR is undefined. See
the DEFINE command for more information.
Example 12-1 Examples
The following example executes the fifth entry in the history list:
HIST[ORY] 5 RUN
The following example allows you to edit the third entry in the history list:
HIST[ORY] 3 EDIT
The following example allows you to delete the second entry from the history list:
HIST[ORY] 2 DEL[ETE]
12-51
Chapter 12
HISTORY
The following example allows you to delete all entries from the history list:
HIST[ORY] CLEAR
The following example shows you how to enable or disable command history, and how
to check the command history status:
SQL> set history on
SQL> show history
History is ON and set to "100"
SQL> set history off
SQL> show history
History is OFF
SQL> set history 1000
SQL> show history
History is ON and set to "1000"
The following example shows you how to list all entries in the history list:
SQL> show history
History is ON and set to "100"
SQL> show user
USER is "SYSTEM"
SQL> desc dual
Name Null? Type
----------------------------------------- -------- ----------------------------
PROD VARCHAR2(1)
D
-
X
D
-
X
SQL> history
1 show history
2 show user
3 desc dual
* 4 select * from dual;
An asterisk (*) indicates the last used command in the command history list.
The following example shows you how to list all entries in the history list, and then
execute the second entry:
SQL> history
1 show history
2 show user
3 desc dual
* 4 select * from dual;
SQL> history 2 run
USER is "SYSTEM"
SQL> history
1 show hist
* 2 show user
12-52
Chapter 12
HOST
3 desc dual
4 select * from dual;
12.27 HOST
Syntax
HO[ST] [command]
Note:
Operating system commands entered from a SQL*Plus session using the
HOST command do not affect the current SQL*Plus session. For example,
setting an operating system environment variable only affects SQL*Plus
sessions started subsequently.
You can disable HOST. For more information about disabling HOST, see
SQL*Plus Security.
Usage
In some operating systems, you can use a character in place of HOST such as "$" in
Windows or "!" in UNIX, or you may not have access to the HOST command. See the
platform-specific Oracle documentation provided for your operating system or ask your
DBA for more information.
On some platforms, an _RC substitution variable may be created with a HOST return
value that is operation system dependent. It is recommended that you do not use the
_RC substitution variable in scripts as it is not portable.
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
SET SQLT[ERMINATOR] {; | c | ON | OFF} for more information.
Examples
To execute a UNIX operating system command, ls *.sql, enter
HOST ls *.sql
12-53
Chapter 12
INPUT
12.28 INPUT
Syntax
I[NPUT] [text]
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:
SELECT LAST_NAME, DEPARTMENT_ID, SALARY, COMMISSION_PCT
FROM EMP_DETAILS_VIEW
2* FROM EMP_DETAILS_VIEW
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:
1 SELECT LAST_NAME, DEPARTMENT_ID, SALARY, COMMISSION_PCT
2 FROM EMP_DETAILS_VIEW
3* ORDER BY LAST_NAME
2* FROM EMP_DETAILS_VIEW
INPUT
3 WHERE JOB_ID = 'SA_MAN'
4 AND COMMISSION_PCT=.25
5
12-54
Chapter 12
LIST
INPUT prompts you for new lines until you enter an empty line or a period. The SQL
buffer now contains the following lines:
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
12.29 LIST
Syntax
L[IST] [n | n m | n * | n LAST | * | * n | * LAST | LAST]
Terms
Term Description
Lists line n.
n
Enter LIST with no clauses, or ";" to list all lines. The last line listed becomes the new
current line (marked by an asterisk).
Examples
To list the contents of the buffer, enter
LIST
or enter
;
12-55
Chapter 12
PASSWORD
To list from the current line (now line 2) to the last line, enter
LIST * LAST
12.30 PASSWORD
Syntax
PASSW[ORD] [username]
where username specifies the user. If omitted, username defaults to the current user.
Enables you to change a password without echoing it on an input device.
Usage
To change the password of another user, you must have been granted the appropriate
privilege. See CONNECT for more information about changing your password.
Examples
If you want to change your current password, enter
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
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.
12-56
Chapter 12
PAUSE
12.31 PAUSE
Syntax
PAU[SE] [text]
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.
See SET PAU[SE] {ON | OFF | text} for information on pausing between pages of a
report.
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:
SET PAUSE OFF
PAUSE Adjust paper and press RETURN to continue.
SELECT ...
12.32 PRINT
Syntax
PRINT [variable ...]
where variable ... represents names of bind variables whose values you want to
display.
Displays the current values of bind variables.
Enter PRINT with no variables to print all bind variables.
Usage
Bind variables are created using the VARIABLE command. See VARIABLE for more
information and examples.
You can control the formatting of the PRINT output just as you would query output. For
more information, see the formatting techniques described in Formatting SQL*Plus
Reports.
12-57
Chapter 12
PROMPT
Examples
The following example illustrates a PRINT command:
VARIABLE n NUMBER
BEGIN
:n := 1;
END;
/
PRINT n
N
----------
1
12.33 PROMPT
Syntax
PRO[MPT] [text]
where text represents the text of the message you want to display.
Sends the specified message or a blank line to the user's screen. 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.SQL. ASKFORDEPT.SQL contains the following
SQL*Plus and SQL commands:
PROMPTPROMPT Please enter a valid departmentPROMPT For example: 10SELECT
DEPARTMENT_NAME FROM EMP_DETAILS_VIEWWHERE DEPARTMENT_ID = &NEWDEPT
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.
12-58
Chapter 12
RECOVER
12.34 RECOVER
Syntax
RECOVER {general | managed | BEGIN BACKUP | END BACKUP}
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 Oracle
Database Administrator's Guide, the ALTER DATABASE RECOVER command in the
12-59
Chapter 12
RECOVER
Oracle Database SQL Language Reference, and the Oracle Database Backup and
Recovery User's Guide guide.
Terms
AUTOMATIC
Automatically generates the name of the next archived redo log file needed to continue
the recovery operation. Oracle Database 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 either accept the generated
filename or replace it with a fully qualified filename. You can save time by using the
LOGFILE clause to specify the filename if you know the archived filename differs from
the filename Oracle Database would generate.
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. 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.
full_database_recovery
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
Specifies a trial recovery to detect possible problems. Redo is applied normally, but no
changes are written to disk, and changes are rolled back at the end of the trial
recovery. You can only use the TEST clause for a trial recovery if you have restored a
backup. 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.
ALLOW integer CORRUPTION
In the event of logfile corruption, specifies the number of corrupt blocks that can be
tolerated while allowing recovery to proceed.
parallel _clause
Enables you to specify the degree of parallel processing to use during the recovery
operation.
12-60
Chapter 12
RECOVER
CONTINUE
Continues recovery using the redo log file generated automatically by Oracle
Database if no other logfile is specified. This is equivalent to specifying AUTOMATIC,
except that Oracle Database does not prompt for a filename.
CANCEL
Recovers the database with a storage snapshot using Storage snapshot Optimization.
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
Specifies an incomplete, time-based recovery. Use single quotes, and the following
format:
'YYYY-MM-DD:HH24:MI:SS'
UNTIL CHANGE
Specifies that a backup of the control file be used instead of the current control file.
TABLESPACE
12-61
Chapter 12
RECOVER
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.
PARALLEL [integer]
SQL*Plus selects a degree of parallelism equal to the number of CPUs available on all
participating instances times the value of the PARALLEL_THREADS_PER_CPU
initialization parameter.
The PARALLEL keyword overrides the RECOVERY_PARALLELISM initialization
parameter. For more information about the PARALLEL keyword see the Oracle Real
Application Clusters Administration and Deployment Guide guide.
Use integer to specify the degree of parallelism, which is the number of parallel
threads used in the parallel operation. Each parallel thread may use one or two
parallel execution processes.
NOPARALLEL
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 Oracle Database
Backup and Recovery User's Guide.
DISCONNECT
Indicates that the managed redo process (MRP) should apply archived redo files as a
detached background process. Doing so leaves the current session available.
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, or if you specify NOTIMEOUT, the database remains
in sustained standby recovery mode until you reissue the statement with the
RECOVER CANCEL clause or until instance shutdown or failure.
NODELAY
12-62
Chapter 12
RECOVER
Applies the specified number of archived redo logs as soon as possible after they have
been archived. It temporarily overrides any DELAY setting in the
LOG_ARCHIVE_DEST_n parameter on the primary database, and any delay values
set in an earlier SQL*Plus RECOVER command or an ALTER DATABASE RECOVER
command.
EXPIRE integer
Specifies the number of minutes from the current time after which managed recovery
terminates automatically.
NO EXPIRE
Recovers redo from standby online logs as they are being filled, without requiring them
to be archived in the standby database first.
UNTIL CHANGE integer
Processes managed recovery up to but not including the specified system change
number (SCN).
THROUGH THREAD integer SEQUENCE integer
Continues managed standby until all archivelogs have been recovered. You can use
this statement to override a THROUGH THREAD integer SEQUENCE integer clause
issued in an earlier statement. If the THROUGH clause is omitted, this is the default.
THROUGH ALL SWITCHOVER
Terminates managed standby recovery after the final end-of-redo archival indicator.
12-63
Chapter 12
RECOVER
Terminates managed standby recovery after recovering the next end-of-redo archival
indicator.
CANCEL (managed clause)
Terminates managed standby recovery after applying the current archived redo file.
Session control returns when the recovery process terminates.
CANCEL IMMEDIATE
Terminates managed standby recovery 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 WAIT
Terminates managed standby recovery after applying the current archived redo file or
after the next redo log file read, whichever comes first. Session control returns when
the managed standby recovery terminates.
CANCEL IMMEDIATE cannot be issued from the same session that issued the
RECOVER MANAGED STANDBY DATABASE statement.
CANCEL IMMEDIATE NOWAIT
Terminates managed standby recovery after applying the current archived redo file, or
after the next redo log file read, whichever comes first. Session control returns
immediately.
CANCEL NOWAIT
Terminates managed standby recovery after the next redo log file read and returns
session control immediately.
FINISH
Recovers the current standby online logfiles of the standby database. This clause may
be useful if the primary database fails. It overrides any delays specified for
archivelogs, so that logs are applied immediately.
FINISH cannot be issued if you have also specified TIMEOUT, DELAY, EXPIRE or
NEXT clauses.
Usage
You must have the OSDBA role enabled. You cannot use the RECOVER command
when connected through 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 or 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).
12-64
Chapter 12
REMARK
Before using the RECOVER command you must have restored copies of the damaged
datafiles 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
RECOVER DATABASE
To recover the two tablespaces ts_one and ts_two from the database, enter
RECOVER TABLESPACE ts_one, ts_two
12.35 REMARK
Syntax
REM[ARK]
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, - -, see About Placing Comments in Scripts.
12-65
Chapter 12
REPFOOTER
Examples
The following script contains some typical comments:
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;
12.36 REPFOOTER
Syntax
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.
Enter REPFOOTER with no clauses to list the current REPFOOTER definition.
Terms
See the REPHEADER command for additional information on terms and clauses in the
REPFOOTER command syntax.
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.
12-66
Chapter 12
REPHEADER
Examples
To define "END EMPLOYEE LISTING REPORT" as a report footer on a separate
page and to center it, enter:
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;
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.
12.37 REPHEADER
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 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.
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
12-67
Chapter 12
REPHEADER
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
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.
12-68
Chapter 12
RUN
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.
12.38 RUN
Syntax
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.
12-69
Chapter 12
SAVE
Examples
Assume the SQL buffer contains the following script:
SELECT DEPARTMENT_ID
FROM EMP_DETAILS_VIEW
WHERE SALARY>12000
1 SELECT DEPARTMENT_ID
2 FROM EMP_DETAILS_VIEW
3 WHERE SALARY>12000
DEPARTMENT_ID
-------------
90
90
90
80
80
20
6 rows selected.
12.39 SAVE
Syntax
SAV[E] [FILE] file_name[.ext] [CRE[ATE] | REP[LACE] | APP[END]]
Terms
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]
12-70
Chapter 12
SET
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). See SET SUF[FIX] {SQL | text} for information on changing
this default extension.
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
SAVE DEPTSALRPT
To save the contents of the buffer in a file named DEPTSALRPT with the extension
OLD, enter
SAVE DEPTSALRPT.OLD
12.40 SET
Sets a system variable to alter the SQL*Plus environment settings for your current
session, for example, to:
• customize HTML formatting
• enable or disable the printing of column headings
• set the number of lines per page
• set the display width for data
Syntax
SET system_variable value
where system_variable and value represent one of the clauses shown in the SET
System Variable Summary table following.
Usage
SQL*Plus maintains system variables (also called SET command variables) to enable
you to set up 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. The
default value for each system variable is underlined in the following sections.
SET ROLE and SET TRANSACTION are SQL commands (see SQL Statements:
MERGE to UPDATE for more information). When not followed by the keywords
TRANSACTION or ROLE, SET is assumed to be a SQL*Plus command.
12-71
Chapter 12
SET System Variable Summary
Sets the number of rows, called a batch, that SQL*Plus will fetch
SET ARRAY[SIZE] {15 | n}
from the database at one time.
Sets the depth of the level to which you can recursively describe
SET DESCRIBE [DEPTH {1 | n | ALL}] [LINENUM
an object.
{ON | OFF}] [INDENT {ON | OFF}]
12-72
Chapter 12
SET System Variable Summary
Sets the starting position from which BLOB, BFILE, CLOB and
SET LOBOF[FSET] {1 | n}
NCLOB data is retrieved and displayed.
Sets the amount of LOB data that SQL*Plus will prefetch from the
SET LOBPREFETCH {0 | n}
database at one time.
Specifies the location from which archive logs are retrieved during
SET LOGSOURCE [pathname]
recovery.
Sets the number of blank lines to be printed from the top of each
SET NEWP[AGE] {1 | n | NONE}
page to the top title.
Sets the text that represents a null value in the result of a SQL
SET NULL text
SELECT command.
12-73
Chapter 12
SET System Variable Summary
Sets the number of rows that SQL*Plus will prefetch from the
SET ROWPREFETCH {15 | n}
database at one time.
Sets how secure column values are displayed for users without
SET SECUREDCOL {OFF | ON} [UNAUTH[ORIZED]
permission to view a column and for columns with unknown
text] [UNK[NOWN] text]
security.
Controls whether to display the output (that is, DBMS_OUTPUT
SET SERVEROUT[PUT] {ON | OFF} [SIZE {n |
PUT_LINE) of stored procedures or PL/SQL blocks in SQL*Plus.
UNL[IMITED]}] [FOR[MAT] {WRA[PPED] |
WOR[D_WRAPPED] | TRU[NCATED]}]
12-74
Chapter 12
SET System Variable Summary
12-75
Chapter 12
SET System Variable Summary
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.
Example
To display the value of APPINFO, as it is SET OFF by default, enter
SET APPINFO ON
SHOW APPINFO
PRINT MOD
MOD
---------------------------------------------------
This is SQL*Plus
12-76
Chapter 12
SET System Variable Summary
Note:
For this feature, a PL/SQL block is considered one transaction, regardless of
the actual number of SQL commands contained within it.
Example
To set the recovery mode to AUTOMATIC, enter
SET AUTORECOVERY ON
RECOVER DATABASE
12-77
Chapter 12
SET System Variable Summary
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. See EXPLAIN PLAN for more information about EXPLAIN PLAN.
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.
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. The additional
information and tabular output of AUTOTRACE PLAN is supported when connecting to
Oracle Database 10g (Release 10.1) or later. When you connect to an earlier
database, the older form or AUTOTRACE reporting is used.
AUTOTRACE is not available when FIPS flagging is enabled.
See About Tracing Statements for more information on AUTOTRACE.
Example
To specify a title with TTITLE and format a column with COLUMN, both on the same
line, enter
SET CMDSEP +
TTITLE LEFT 'SALARIES' + COLUMN SALARY FORMAT $99,999
SELECT LAST_NAME, SALARY FROM EMP_DETAILS_VIEW
WHERE JOB_ID = 'SH_CLERK';
SALARIES
LAST_NAME SALARY
------------------------- --------
Taylor $3,200
12-78
Chapter 12
SET System Variable Summary
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.
Example
To view information about an invisible column with the DESCRIBE command.
Create a table with an invisible column.
create table test_invisible_cols (emp_id number, emp_info char(20),
emp_acc_no number invisible);
Table created.
Note that with the default SET COLINVISIBLE OFF, the invisible column does not
appear in the result. Change the default setting of SET COLINVISIBLE to ON.
SET COLINVISIBLE ON
colinvisible ON
12-79
Chapter 12
SET System Variable Summary
Now use the DESCRIBE command again to list the table columns. The invisible
column now appears in the output.
describe test_invisible_cols
Example
To set the column separator to "|" enter
SET MARKUP HTML PREFORMAT ON
SET COLSEP '|'
SELECT LAST_NAME, JOB_ID, DEPARTMENT_ID
FROM EMP_DETAILS_VIEW
WHERE DEPARTMENT_ID = 20;
12-80
Chapter 12
SET System Variable Summary
Example
To create an object type ADDRESS, enter
CREATE TYPE ADDRESS AS OBJECT
( STREET VARCHAR2(20),
CITY VARCHAR2(20)
);
/
Type created
To create the table EMPLOYEE that contains a nested object, EMPADDR, of type
ADDRESS, enter
CREATE TABLE EMPLOYEE
(LAST_NAME VARCHAR2(30),
EMPADDR ADDRESS,
JOB_ID VARCHAR2(20),
SALARY NUMBER(7,2)
);
/
Table created
12-81
Chapter 12
SET System Variable Summary
To describe the table EMPLOYEE to a depth of two levels, and to indent the output
and display line numbers, enter:
SET DESCRIBE DEPTH 2 LINENUM ON INDENT ON
DESCRIBE employee
12-82
Chapter 12
SET System Variable Summary
If an internal error occurs, to avoid recursion errors caused by the errorlog calling
itself, errorlogging is automatically set OFF.
Error logging is set OFF by default.
ON
Writes ORA, PLS and SP2 errors to the default table, SPERRORLOG.
OFF
Disables error .
TABLE [schema.]tablename
Specifies a user defined table to use instead of the default, SPERRORLOG. If you
omit schema. the table is created in the current schema. The table you specify must
exist, and you must have access permissions.
If the table specified does not exist, or you do not have access, an error message is
displayed and the default table, SPERRORLOG, is used.
TRUNCATE
Clears all existing rows in the error log table and begins recording errors from the
current session.
IDENTIFIER identifier
A user defined string to identify errors. You can use it to identify errors from a
particular session or from a particular version of a query.
12-83
Chapter 12
SET System Variable Summary
Example
To use the default error log table to record query errors from a script, myfile.sql, which
contains the following:
VARIABLE U REFCURSOR
BEGIN
OPEN :U FOR SELECT * FROM DEPT;
END;
/
SET GARBAGE
SELECT *
FROM
GARBAGE
;
ERROR:
ORA-00907: missing right parenthesis
garbage
*
ERROR at line 3:
ORA-00942: table or view does not exist
To view the errror log written to the default error log table, SPERRORLOG, enter:
SELECT TIMESTAMP, USERNAME, SCRIPT, IDENTIFIER, STATEMENT, MESSAGE
FROM SPERRORLOG;
12-84
Chapter 12
SET System Variable Summary
Example 2
To use a user defined error log table to record query errors from a script, myfile.sql,
which contains the following:
VARIABLE U REFCURSOR
BEGIN
OPEN :U FOR SELECT * FROM DEPT;
END;
/
SET GARBAGE
SELECT *
FROM
GARBAGE
;
ERROR:
12-85
Chapter 12
SET System Variable Summary
garbage
*
ERROR at line 3:
ORA-00942: table or view does not exist
To view the errror log written to the default error log table, SPERRORLOG, enter:
SELECT TIMESTAMP, USERNAME, SCRIPT, IDENTIFIER, STATEMENT, MESSAGE
FROM SPERRORLOG;
Example 3
To use an error log table other than the default:
• Create the error log table you want to use
• Specify the table you want to use with the TABLE option of the SET
ERRORLOGGING ON command.
The error log table must have the column definitions defined in Table 12-4.
John wants to use an error log table named john_sperrorlog. John would run the
following SQL statements to create the new error log table:
DROP TABLE john_sperrorlog;
CREATE TABLE john_sperrorlog(username VARCHAR(256),
timestamp TIMESTAMP,
script VARCHAR(1024),
identifier VARCHAR(256),
message CLOB,
statement CLOB);
12-86
Chapter 12
SET System Variable Summary
Removed Commit from previous example from user comment giridhar123 14Feb08
John then issues the following SET command to enable error logging using the newly
created error log table
SET ERRORLOGGING ON TABLE john_sperrorlog
All error logging for John is now recorded to john_sperrorlog, and not to the default
error log table, SPERRORLOG.
Access privileges for the error log table are handled in the same way as for any user
table.
Example
If you define the escape character as an exclamation point (!), then
SET ESCAPE !
ACCEPT v1 PROMPT 'Enter !&1:'
To set the escape character back to the default value of \ (backslash), enter
SET ESCAPE ON
12-87
Chapter 12
SET System Variable Summary
Example
If you include the character '$' in your filename, then
SET ESCCHAR $
RUN MYFILE$
behaves normally.
12-88
Chapter 12
SET System Variable Summary
Example
To enable SET FEEDBACK ONLY, enter
SQL> SET FEEDBACK ONLY
SQL> SHOW FEEDBACK
feedback ONLY
SQL> SELECT * FROM EMP;
14 rows selected.
Example
To suppress the display of column headings in a report, enter
SET HEADING OFF
12-89
Chapter 12
SET System Variable Summary
Examples
To enable command history and store 200 entries in the list, enter
SET HIST[ORY] 200
Note:
Multiline entries such as PL/SQL blocks are considered as one single entry in
the command history list. You can store up to 100000 commands in command
history. If you try to enable command history while it is already enabled, the
old command history is cleared.
12-90
Chapter 12
SET System Variable Summary
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 Database 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
DISCONNECT
SET INSTANCE PROD1
You must disconnect from any connected instances to change the instance.
Example
To set the starting position from which a CLOB column's data is retrieved to the 22nd
position, enter
SET LOBOFFSET 22
The CLOB data will wrap on your screen; SQL*Plus will not truncate until the 23rd
character.
12-91
Chapter 12
SET System Variable Summary
Example
To set the amount of prefetched LOB data to 8000 bytes, enter
SET LOBPREFETCH 8000
If you do not specify a value for n, the default is 0. This means that LOB data
prefetching is off.
Note:
You can specify a maximum value of 2147483648 bytes (2 Gigabytes). The
settings in the oraaccess.xml file can override the SET LOBPREFETCH setting
in SQL*Plus. For more information about oraaccess.xml, see the Oracle Call
Interface Programmer's Guide.
To show the current setting for the amount of LOB data that SQL*Plus will prefetch
from the database at one time, enter
SHOW LOBPREF[ETCH]
Example
To set the default location of log files for recovery to the directory "/usr/oracle10/dbs/
arch" enter
SET LOGSOURCE "/usr/oracle10/dbs/arch"
RECOVER DATABASE
12-92
Chapter 12
SET System Variable Summary
assumes that available RAM (random access memory) on the machine exceeds 2
gigabytes.
Example
To set the maximum number of bytes to fetch for displaying and copying LONG
values, to 500, enter
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.
Example
To set the size of the increments in which SQL*Plus retrieves LONG values to 100
bytes, enter
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.
csv_option
Outputs reports in CSV format.
To be effective, SET MARKUP commands that change values in dynamic report
output must be issued before the statement that produces the query output. The first
12-93
Chapter 12
SET System Variable Summary
statement that produces the query output triggers the output of CSV data that reflects
the DELIMITER and QUOTE settings.
CSV is a mandatory SET MARKUP argument which specifies the type of output to be
generated is CSV. The optional CSV arguments, ON and OFF, specify whether or not
to generate CSV output. The default is OFF.
You can turn CSV output ON and OFF as required during a session.
DELIMI[TER] character
The QUOTE {ON|OFF} option enables you to turn text quoting on or off. The default is
OFF.
QUOTE ON generates CSV output with all text quoted. Double quotes (“ ”) embedded
within text are escaped.
You can turn quoted text ON and OFF as required during a session.
12-94
Chapter 12
SET System Variable Summary
• SET PAUSE
• SET RECSEP
• SET SHIFTINOUT
• SET TAB
• SET TRIMOUT
• SET TRIMSPOOL
• SET UNDERLINE
• SET WRAP
When SET MARKUP CSV is enabled, the following COLUMN commands will have no
effect on the output:
• COLUMN ENTMAP
• COLUMN FOLD_AFTER
• COLUMN FOLD_BEFORE
• COLUMN JUSTIFY
• COLUMN NEWLINE
• COLUMN NEW_VALUE
• COLUMN NOPRINT
• COLUMN OLD_VALUE
• COLUMN WRAP
Use the SHOW MARKUP command to view the status of MARKUP options.
Example
The following example illustrates the output when SET MARKUP CSV is enabled:
SQL> SET MARKUP CSV ON
SQL> SELECT * FROM EMP;
"EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO"
7369,"SMITH","CLERK",7902,"17-DEC-80",800,,20
7499,"ALLEN","SALESMAN",7698,"20-FEB-81",1600,300,30
7521,"WARD","SALESMAN",7698,"22-FEB-81",1250,500,30
7566,"JONES","MANAGER",7839,"02-APR-81",2975,,20
7654,"MARTIN","SALESMAN",7698,"28-SEP-81",1250,1400,30
7698,"BLAKE","MANAGER",7839,"01-MAY-81",2850,,30
7782,"CLARK","MANAGER",7839,"09-JUN-81",2450,,10
7788,"SCOTT","ANALYST",7566,"19-APR-87",3000,,20
7839,"KING","PRESIDENT",,"17-NOV-81",5000,,10
7844,"TURNER","SALESMAN",7698,"08-SEP-81",1500,0,30
7876,"ADAMS","CLERK",7788,"23-MAY-87",1100,,20
7900,"JAMES","CLERK",7698,"03-DEC-81",950,,30
7902,"FORD","ANALYST",7566,"03-DEC-81",3000,,20
7934,"MILLER","CLERK",7782,"23-JAN-82",1300,,10
14 rows selected.
The following example illustrates how to extract all records from the Employee table of
the database, with text strings unquoted:
12-95
Chapter 12
SET System Variable Summary
EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO
7369,SMITH,CLERK,7902,17-DEC-80,800,,20
7499,ALLEN,SALESMAN,7698,20-FEB-81,1600,300,30
7521,WARD,SALESMAN,7698,22-FEB-81,1250,500,30
7566,JONES,MANAGER,7839,02-APR-81,2975,,20
7654,MARTIN,SALESMAN,7698,28-SEP-81,1250,1400,30
7698,BLAKE,MANAGER,7839,01-MAY-81,2850,,30
7782,CLARK,MANAGER,7839,09-JUN-81,2450,,10
7788,SCOTT,ANALYST,7566,19-APR-87,3000,,20
7839,KING,PRESIDENT,,17-NOV-81,5000,,10
7844,TURNER,SALESMAN,7698,08-SEP-81,1500,0,30
7876,ADAMS,CLERK,7788,23-MAY-87,1100,,20
7900,JAMES,CLERK,7698,03-DEC-81,950,,30
7902,FORD,ANALYST,7566,03-DEC-81,3000,,20
7934,MILLER,CLERK,7782,23-JAN-82,1300,,10
14 rows selected.
The following example illustrates the output with the pipe ( | ) character specified as
the delimiter:
SQL> SET MARKUP CSV ON DELIMITER |
SQL> SELECT * FROM EMP;
EMPNO|ENAME|JOB|MGR|HIREDATE|SAL|COMM|DEPTNO
7369|SMITH|CLERK|7902|17-DEC-80|800||20
7499|ALLEN|SALESMAN|7698|20-FEB-81|1600|300|30
7521|WARD|SALESMAN|7698|22-FEB-81|1250|500|30
7566|JONES|MANAGER|7839|02-APR-81|2975||20
7654|MARTIN|SALESMAN|7698|28-SEP-81|1250|1400|30
7698|BLAKE|MANAGER|7839|01-MAY-81|2850||30
7782|CLARK|MANAGER|7839|09-JUN-81|2450||10
7788|SCOTT|ANALYST|7566|19-APR-87|3000||20
7839|KING|PRESIDENT||17-NOV-81|5000||10
7844|TURNER|SALESMAN|7698|08-SEP-81|1500|0|30
7876|ADAMS|CLERK|7788|23-MAY-87|1100||20
7900|JAMES|CLERK|7698|03-DEC-81|950||30
7902|FORD|ANALYST|7566|03-DEC-81|3000||20
7934|MILLER|CLERK|7782|23-JAN-82|1300||10
14 rows selected.
html_option
Outputs HTML marked up text.
To be effective, SET MARKUP commands that change values in dynamic report
output must occur before statements that produce query output. The first statement
that produces query output triggers the output of information affected by SET
MARKUP such as HEAD and TABLE settings. Subsequent SET MARKUP commands
have no effect on the information already sent to the report.
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.
12-96
Chapter 12
SET System Variable Summary
See MARKUP Options for detailed information. For examples of usage, see
Generating HTML Reports from SQL*Plus.
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.
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:
START employee.sql
As well as writing the HTML spool file, employee.htm, 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:
12-97
Chapter 12
SET System Variable Summary
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.
12-98
Chapter 12
SET System Variable Summary
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.
Example
To set the number of prefetched rows to 200, enter
SET ROWPREFETCH 200
If you do not specify a value for n, the default is 1 row. This means that row
prefetching is off.
Note:
The amount of data contained in the prefetched rows should not exceed the
maximum value of 2147483648 bytes (2 Gigabytes). The <prefetch> setting
in the oraaccess.xml file can override the SET ROWPREFETCH setting in
SQL*Plus. For more information about oraaccess.xml, see the Oracle Call
Interface Programmer's Guide.
To show the current setting for the number of rows that SQL*Plus will prefetch from
the database at one time, enter
SHOW ROWPREF[ETCH]
12-99
Chapter 12
SET System Variable Summary
ON displays the default indicator "*****" in place of column values for users without
authorisation, and displays "?????" in place of column values where the security level
is unknown. The indicators "*" and "?" are filled to the defined column length or the
column length defined by a current COLUMN command.
OFF displays null values in place of column values for users without authorization, and
in place of column values where the security level is unknown.
UNAUTH[ORIZED] text enables you to specify the text to be displayed in a secured
column for users without authorization. This text appears instead of the default "*****"
You can specify any alpha numeric text up to the column length or a maximum of 30
characters. Longer text is truncated. Text containing spaces must be quoted.
UNK[NOWN] text enables you to specify the text to be displayed in a column of
unknown security level. This text appears instead of the default "??????"
You can specify any alpha numeric text up to the column length or a maximum of 30
characters. Longer text is truncated. Text containing spaces must be quoted.
Example
SET SECUREDCOL ON
SELECT empno, ename, sal FROM emp ORDER BY deptno;
12-100
Chapter 12
SET System Variable Summary
SIZE sets the number of bytes of the output that can be buffered within the Oracle
Database server. The default is UNLIMITED. n cannot be less than 2000 or greater
than 1,000,000.
Resources are not pre-allocated when SERVEROUTPUT is set. As there is no
performance penalty, use UNLIMITED unless you want to conserve physical memory.
Every server output line begins on a new output line.
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 detailed information about using UTL_FILE and associated utilities, see the Oracle
Database PL/SQL Packages and Types Reference .
For more information on DBMS_OUTPUT.PUT_LINE, see Developing Applications
with Oracle XA.
Example
To enable text display in a PL/SQL block using DBMS_OUTPUT.PUT_LINE, enter
SET SERVEROUTPUT ON
The following example shows what happens when you execute an anonymous
procedure with SET SERVEROUTPUT ON:
BEGIN
DBMS_OUTPUT.PUT_LINE('Task is complete');
END;
/
Task is complete.
PL/SQL procedure successfully completed.
The following example shows what happens when you create a trigger with SET
SERVEROUTPUT ON:
CREATE TABLE SERVER_TAB (Letter CHAR);
CREATE TRIGGER SERVER_TRIG BEFORE INSERT OR UPDATE -
OR DELETE
ON SERVER_TAB
BEGIN
DBMS_OUTPUT.PUT_LINE('Task is complete.');
END;
/
Trigger Created.
12-101
Chapter 12
SET System Variable Summary
Task is complete.
1 row created.
If there is nothing
left to do
shall we continue
with plan B?
If there is nothing
shall we continue wi
Example
To enable the display of shift characters on a terminal that supports them, enter
SET SHIFTINOUT VISIBLE
SELECT LAST_NAME, JOB_ID FROM EMP_DETAILS_VIEW
WHERE SALARY > 12000;
LAST_NAME JOB_ID
---------- ----------
:JJOO: :AABBCC:
:AA:abc :DDEE:e
12-102
Chapter 12
SET System Variable Summary
Example
To allow blank lines in a SQL statement, enter
SET SQLBLANKLINES ON
REM Using the SQLTERMINATOR (default is ";")
REM Could have used the BLOCKTERMINATOR (default is ".")
SELECT *
FROM
DUAL
12-103
Chapter 12
SET System Variable Summary
Example
To set the SQL*Plus command continuation prompt to an exclamation point followed
by a space, enter
SET SQLCONTINUE '! '
12-104
Chapter 12
SET System Variable Summary
Example
To change your SQL*Plus prompt to display your connection identifier, enter:
SET SQLPROMPT "_CONNECT_IDENTIFIER > "
To set the SQL*Plus command prompt to show the current user, enter
12-105
Chapter 12
SET System Variable Summary
To change your SQL*Plus prompt to display your the current date, the current user
and the users privilege level, enter:
SET SQLPROMPT "_DATE _USER _PRIVILEGE> "
To change your SQL*Plus prompt to display a variable you have defined, enter:
DEFINE mycon = Prod1
SET SQLPROMPT "mycon> "
Prod1>
Text in nested quotes is not parsed for substitution. To have a SQL*Plus prompt of
your username, followed by "@", and then your connection identifier, enter:
SET SQLPROMPT "_USER'@'_CONNECT_IDENTIFIER > "
Example
To set the statement cache size to 15, enter
SET STATEMENTCACHE 15
If you do not specify a value for n, the default is 0. This means that statement caching
is off.
The statement cache size can be any value between 0 and 32767.
12-106
Chapter 12
SET System Variable Summary
Note:
Specify a cache size that is less than the value specified for the open cursor
parameter in the Oracle Database initialization file, init.ora. Specifying a value
of 0 will switch off statement caching. The <statement_cache> setting in
the oraaccess.xml file can override the SET STATEMENTCACHE setting in
SQL*Plus. For more information about oraaccess.xml, see the Oracle Call
Interface Programmer's Guide.
To show the current setting for the statement cache size, enter
SHOW STATEMENTC[ACHE]
Example
To change the default command-file extension from the default, .SQL to .TXT, enter
SET SUFFIX TXT
12-107
Chapter 12
SET System Variable Summary
ON displays timing statistics on each SQL command or PL/SQL block run. OFF
suppresses timing of each command.
See TIMING for information on timing multiple commands.
Example
The format of timing statistics is dependent on the operating system. In Linux and
Windows, the timing statistics are in 24 hour format displaying hours, minutes,
seconds and hundredths of seconds
SET SUFFIX TXT
If you enter
GET EXAMPLE
12-108
Chapter 12
SET System Variable Summary
Take care to enter valid values as values are checked only when an XQUERY
command is issued.
Example
SET XQUERY BASEURI '/public/scott'
XQUERY for $i in doc("foo.xml") return $i
/
Example
SET XQUERY ORDERING ORDERED
XQUERY for $i in doc("foo.xml") return $i
/
12-109
Chapter 12
SET System Variable Summary
Example
SET XQUERY NODE BYREFERENCE
XQUERY for $i in doc("foo.xml") return $i
/
Take care to enter valid values as values are checked only when an XQUERY
command is issued.
Example
SET XQUERY CONTEXT 'doc("foo.xml")'
XQUERY for $i in /a return $i
/
12-110
Chapter 12
SHOW
12.42 SHOW
Syntax
SHO[W] option
Shows the value of a SQL*Plus system variable or the current SQL*Plus environment.
SHOW SGA requires a DBA privileged login.
Terms
system_variable
Lists the settings of all SHOW options, except ERRORS and SGA, in alphabetical
order.
CON_ID
Displays the id of the Container to which you are connected when connected to a
Consolidated Database. If issued when connected to a non-Consolidated Database,
this command returns 0.
CON_NAME
Displays the name of the Container to which you are connected when connected to a
Consolidated Database. For non-consolidated database, it will return "Non
Consolidated".
EDITION
12-111
Chapter 12
SHOW
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 (analytic view, attribute dimension, hierarchy, 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 use the COLUMN command to alter the default widths.
HISTORY
Shows the current command history status that is set by using the SET HISTORY
command.
LNO
Shows the current line number (the position in the current page of the display and/or
spooled output).
LOBPREFETCH
Shows the current setting for the amount of LOB data that SQL*Plus will prefetch from
the database at one time. For more information about setting the amount of LOB data
that SQL*Plus will prefetch from the database at one time, see SET LOBPREFETCH.
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:
SHOW PARAMETERS COUNT
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
PDBS
12-112
Chapter 12
SHOW
Display the names, ids, mode and restriction status of Pluggable Databases in the
Consolidated Database to which you are connected. The command is not available if
you are connected to a non-Consolidated Database.
The PDBS option is only available when logged in with DBA privileges. For non-DBA
users, attempting to use the PDBS option returns the error SP2-0382: The SHOW
PDBS command is not available.
PNO
Shows objects in the recycle bin that can be reverted with the FLASHBACK BEFORE
DROP command. You do not need to remember column names, or interpret the less
readable output from the query:
SELECT * FROM USER_RECYCLEBIN
Shows the current setting for the number of rows that SQL*Plus will prefetch from the
database at one time. For more information about setting the number of rows that
SQL*Plus will prefetch from the database at one time, see SET ROWPREFETCH.
SPOO[L]
12-113
Chapter 12
SHOW
Displays information about the current instance's System Global Area. You need
SELECT ON V_$SGA object privileges otherwise you will receive a message
ORA-00942: table or view does not exist
SPPARAMETERS [parameter_name]
Shows the value of SQL.SQLCODE (the SQL return code of the most recent
operation).
STATEMENTCACHE
Shows the current setting for the statement cache size. For more information about
setting the statement cache size, see SET STATEMENTCACHE.
TTI[TLE]
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"
XQUERY
Shows the current values of the XQUERY settings, BASEURI, CONTEXT, NODE and
ORDERING.
xquery BASEURI "public/scott" CONTEXT "doc("test.xml")" NODE byreference ORDERING
ordered
Examples
To display information about the SGA, enter
SHOW SGA
12-114
Chapter 12
SHOW
The following example illustrates how to create a stored procedure and then show its
compilation errors:
CONNECT SYSTEM/MANAGER
CREATE PROCEDURE HR.PROC1 AS
BEGIN
:P1 := 1;
END;
/
NO ERRORS.
AUTORECOVERY ON
CON_ID
------------------------------
1
To display the name of the container to which you are connected, enter
SHOW CON_NAME
CON_NAME
------------------------------
CDB$ROOT
To display the current command history status that is set by issuing the SET
HIST[ORY] {ON | OFF | n} command, enter
SHOW HISTORY
12-115
Chapter 12
SHUTDOWN
To display the names, ids, and modes of Pluggable Databases in the Consolidated
Database to which you are connected, enter
SHOW PDBS
INSTANCE "LOCAL"
LOGSOURCE "/usr/oracle90/dbs/arch"
To display objects that can be reverted with the FLASHBACK commands where CJ1
and ABC were objects dropped, enter:
SHOW RECYCLEBIN
12.43 SHUTDOWN
Syntax
SHUTDOWN [ABORT | IMMEDIATE | NORMAL | TRANSACTIONAL [LOCAL]]
Shuts down a currently running Oracle Database instance, optionally closing and
dismounting a database. If the current database is a pluggable database, only the
pluggable database is closed. The consolidated instance continues to run.
Shutdown commands that wait for current calls to complete or users to disconnect
such as SHUTDOWN NORMAL and SHUTDOWN TRANSACTIONAL have a time
limit that the SHUTDOWN command will wait. If all events blocking the shutdown have
not occurred within the time limit, the shutdown command cancels with the following
message:
ORA-01013: user requested cancel of current operation
12-116
Chapter 12
SHUTDOWN
Terms
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]
Usage
SHUTDOWN with no arguments is equivalent to SHUTDOWN NORMAL.
12-117
Chapter 12
SPOOL
Examples
If logged into a CDB, shutdown closes the CDB instance.
To shutdown a CDB or non CDB, you must be connected to the CDB or non CDB
instance that you want to close, and then enter
SHUTDOWN
Database closed.
Database dismounted.
Oracle instance shut down.
To shutdown a PDB, you must log into the PDB to issue the SHUTDOWN command.
SHUTDOWN
12.44 SPOOL
Syntax
SPO[OL] [file_name[.ext] [CRE[ATE] | REP[LACE] | APP[END]] | OFF | OUT]
Terms
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). The
extension is not appended to system files such as /dev/null and /dev/stderr.
CRE[ATE]
Replaces the contents of an existing file. If the file does not exist, REPLACE creates
the file. This is the default behavior.
APP[END]
Adds the contents of the buffer to the end of the file you specify.
OFF
Stops spooling.
OUT
12-118
Chapter 12
START
Stops spooling and sends the file to your 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 that run interactively.
You must use quotes around file names containing white space.
To create a valid HTML file using SPOOL APPEND commands, you must use
PROMPT or a similar command to create the HTML page header and footer. The
SPOOL APPEND command does not parse HTML tags.
SET SQLPLUSCOMPAT[IBILITY] to 9.2 or earlier to disable the CREATE, APPEND
and SAVE parameters. See SQL*Plus Compatibility Matrix to determine what
functionality is controlled by the SET SQLPLUSCOMPAT[IBILITY] command.
To record your output to the file DIARY, overwriting the existing content, enter
SPOOL DIARY REPLACE
To stop spooling and print the file on your default printer, enter
SPOOL OUT
12.45 START
Syntax
STA[RT] {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.
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]
12-119
Chapter 12
START
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). See SET SUF[FIX] {SQL | text} for information on changing
the default extension.
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. See the platform-specific Oracle
documentation 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.
See Defining Substitution Variables and Using Substitution Variables for more
information on using parameters.
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 also disables the @ and
@@ commands. See @ (at sign) and @@ (double at sign) for further information on
these commands. See Disabling SQL*Plus_ SQL_ and PL/SQL Commands for
more information.
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:
SELECT FIRST_NAME, LAST_NAME, JOB_ID, SALARYFROM EMP_DETAILS_VIEWWHERE JOB_ID='&1'
AND SALARY>&2;
12-120
Chapter 12
STARTUP
12.46 STARTUP
Syntax
STARTUP db_options | cdb_options | upgrade_options
Starts an Oracle Database instance with several options, including mounting and
opening a database.
12-121
Chapter 12
STARTUP
• The PDB must be in READ ONLY or READ WRITE mode to be in mounted mode.
For more information, see the Oracle Database Administrator's Guide
Note:
Only use db_options to start a Database (Consolidated or otherwise)
Only use root_connection_options to start a Pluggable Database while
connected to the Root.
Only use pdb_options to start a Pluggable Database to which you are
connected.
Only use upgrade_options to start a Database (Consolidated or otherwise) for
upgrade or downgrade.
If neither READ WRITE nor READ ONLY is specified, a PDB will be opened in READ
ONLY if a CDB to which it belongs is used as a physical standby database,
otherwise the PDB will be opened READ WRITE.
For more information about using Consolidated and Pluggable Databases, see
Creating and Configuring an Oracle Database.
Terms
FORCE
Shuts down the current Oracle Database 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 enables Oracle Database 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
Specifies the client parameter file to be used while starting the instance. If PFILE is not
specified, the server attempts to access a default server parameter file (spfile). If the
default spfile isn't found, the server then attempts to access a default pfile. The default
files are 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
12-122
Chapter 12
STARTUP
OPEN
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.
UPGRADE
Starts the database in OPEN UPGRADE mode and sets system initialization
parameters to specific values required to enable database upgrade scripts to be run.
UPGRADE should only be used when a database is first started with a new version of
the Oracle Database Server.
When run, upgrade scripts transform an installed version or release of an Oracle
database into a later version, for example, to upgrade an Oracle9i database to Oracle
Database 10g. Once the upgrade completes, the database should be shut down and
restarted normally.
DOWNGRADE
Starts the database in OPEN DOWNGRADE mode and sets system initialization
parameters to specific values required to enable database downgrade scripts to be
run.
When run, downgrade scripts transform an installed version or release of Oracle
Database into a previous version, for example, to downgrade an Oracle10g database
to an Oracle9i database. Once the downgrade completes, the database should be
shut down and restarted normally.
PLUGGABLE DATABASE
Use the pluggable database pdbname option to specify the plugggable database on
which you want the STARTUP command to act.
Usage
You must be connected to a database as SYSDBA, SYSOPER, SYSBACKUP, or
SYSDG. You cannot be connected to a shared server via a dispatcher.
STARTUP with no arguments is equivalent to STARTUP OPEN.
STARTUP OPEN RECOVER mounts and opens the database even when recovery
fails.
12-123
Chapter 12
STARTUP
Examples
To start a CDB or non CDB instance using the standard parameter file, mount the
default database, and open the database, enter
STARTUP
or enter
STARTUP OPEN database
To start an instance using the standard parameter file, mount the default database,
and open the database, enter
STARTUP FORCE RESTRICT MOUNT
To start an instance using the parameter file TESTPARM without mounting the
database, enter
STARTUP PFILE=testparm NOMOUNT
To shutdown a particular database, immediately restart and open it, allow access only
to users with the RESTRICTED SESSION privilege, and use the parameter file
MYINIT.ORA. enter
STARTUP FORCE RESTRICT PFILE=myinit.ora OPEN database
STARTUP MOUNT
Connected.
SHOW CON_NAME
CON_NAME
------------------------------
CDB1_PDB1
SHOW PDBS
12-124
Chapter 12
STORE
STARTUP
SHOW PDBS
Connected.
SHOW CON_NAME
CON_NAME
------------------------------
CDB$ROOT
SHOW PDBS
SHOW PDBS
12.47 STORE
Syntax
STORE SET file_name[.ext] [ CRE[ATE | REP[LACE] | APP[END]]
Terms
See SAVE for information on the other terms and clauses in the STORE command
syntax.
SET
12-125
Chapter 12
TIMING
Usage
This command creates a script which can be executed with the START, @ (at sign) or
@@ (double at sign) 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
STORE SET DEFAULTENV
12.48 TIMING
Syntax
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
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, 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.
See the SET TIMING command for information on automatically displaying timing data
after each SQL command or PL/SQL block you run.
12-126
Chapter 12
TTITLE
Examples
To create a timer named SQL_TIMER, enter
TIMING START SQL_TIMER
To list the current timer's title and accumulated time and to remove the timer, enter
TIMING STOP
12.49 TTITLE
Syntax
TTI[TLE] [printspec [text | variable] ...] [ON | OFF]
where printspec represents one or more of the following clauses used to place and
format the text:
BOLD CE[NTER] COL n FORMAT text LE[FT] R[IGHT] S[KIP] [n] TAB n
Places and formats a specified title at the top of each report page. Enter TTITLE with
no clauses to list its current definition. The old form of TTITLE is used if only a single
word or string in quotes follows the TTITLE command.
See TTI[TLE] text (obsolete old form) for a description of the old form of TTITLE.
Terms
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
12-127
Chapter 12
TTITLE
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 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.
Enter TTITLE with no clauses to list the current TTITLE definition.
12-128
Chapter 12
UNDEFINE
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 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
TTITLE LEFT 'Monthly Analysis' CENTER '01 Jan 2003' -
RIGHT 'Page:' FORMAT 999 SQL.PNO SKIP CENTER -
'Data in Thousands'
To suppress the top title display without changing its definition, enter
TTITLE OFF
12.50 UNDEFINE
Syntax
UNDEF[INE] variable ...
where variable represents the name of the substitution variable you want to delete.
Deletes one or more substitution variables that you defined either explicitly (with the
DEFINE command) or implicitly (with an argument to the START command).
Examples
To undefine a substitution variable named POS, enter
UNDEFINE POS
12-129
Chapter 12
VARIABLE
12.51 VARIABLE
Syntax
VAR[IABLE] [variable [type [=value]]]
Declares a bind variable that can be referenced in PL/SQL, or lists the current display
characteristics for a single variable or all variables.
type represents one of the following:
NUMBER CHAR CHAR (n [CHAR | BYTE]) NCHAR NCHAR (n) VARCHAR2 (n [CHAR | BYTE])
NVARCHAR2 (n) CLOB NCLOB REFCURSOR BINARY_FLOAT BINARY_DOUBLE
VARIABLE without arguments displays a list of all the variables declared in the
session. VARIABLE followed only by a variable name lists that variable.
To free resources used by CLOB and NCLOB bind variables, you may need to
manually free temporary LOBs with:
EXECUTE DBMS_LOB.FREETEMPORARY(:cv)
See About Using Bind Variables for more information on bind variables. See your
Oracle Database PL/SQL Language Reference for more information about PL/SQL.
Terms
variable
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
12-130
Chapter 12
VARIABLE
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])
Note:
By default, the maximum VARCHAR2 length is 4000 bytes. Attempting to use
a maximum length greater than 4000 bytes raises ORA-01460 :
unimplemented or unreasonable conversion requested
To enable 32k maximum length, you must add the
MAX_STRING_SIZE=extended parameter to your init.ora file.
NVARCHAR2 (n)
Note:
By default, , the maximum NVARCHAR2 length is 4000 bytes. Attempting to
use a maximum length greater than 4000 bytes raises ORA-01460 :
unimplemented or unreasonable conversion requested
To enable 32k maximum length, you must add the
MAX_STRING_SIZE=extended parameter to your init.ora file.
CLOB
12-131
Chapter 12
VARIABLE
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. See PRINT for more information.
To automatically display the value of a bind variable created with VARIABLE, use the
SET AUTOPRINT command. See SET AUTOP[RINT] {ON | OFF} for more
information.
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 when you exit SQL*Plus.
To free resources used by CLOB and NCLOB bind variables, you may need to
manually free temporary LOBs with:
EXECUTE DBMS_LOB.FREETEMPORARY(:cv)
12-132
Chapter 12
VARIABLE
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, changing its value, and
displaying its current value.
To create a bind variable, enter:
VARIABLE ret_val NUMBER
To change this bind variable in SQL*Plus, you must use a PL/SQL block:
BEGIN
:ret_val:=4;
END;
/
RET_VAL
----------
4
The following example illustrates creating a bind variable and then setting it to the
value returned by a function:
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:
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;
/
12-133
Chapter 12
VARIABLE
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:
VARIABLE id NUMBER
VARIABLE txt CHAR (20)
VARIABLE myvar REFCURSOR
variable id
datatype NUMBER
variable txt
datatype CHAR(20)
variable myvar
datatype REFCURSOR
variable txt
datatype CHAR(20)
The following example illustrates assigning a value to a variable for input binding:
VARIABLE tmp_var VARCHAR2(10)=Smith
The following example illustrates an alternate method to achieve the same result as
the previous example:
VARIABLE tmp_var VARCHAR2(10)
VARIABLE tmp_var=Smith
EXECUTE DBMS_OUTPUT.PUT_LINE(:tmp_var)
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:
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;
12-134
Chapter 12
VARIABLE
END;
/
------------
Total: $98,500.00
The following example illustrates how to create an input bind to insert CLOB data into
a CLOB column:
SQL> create table xyz (col1 clob);
Table created.
1 row created.
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.
12-135
Chapter 12
WHENEVER OSERROR
VARIABLE T CLOB
BEGIN
SELECT CLOB_COL INTO :T FROM CLOB_TAB;
END;
/
T
----------------------------------------------------------------------
Remember to run the Departmental Salary Bill report each month This r
eport contains confidential information.
T
----------------------------------------------------------------------
Departmental Salary Bill report each month This report contains confi
dential information.
Performs the specified action (exits SQL*Plus by default) if an operating system error
occurs (such as a file writing error).
Terms
[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 for more information.
CONTINUE
12-136
Chapter 12
WHENEVER SQLERROR
Directs SQL*Plus to execute a COMMIT before exiting or continuing and save pending
changes to the database.
ROLLBACK
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
If a failure occurs when reading from the output file, the commands in the following
script cause SQL*Plus to exit and COMMIT any pending changes:
WHENEVER OSERROR EXIT
START no_such_file
Terms
[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 for more information.
CONTINUE
12-137
Chapter 12
WHENEVER SQLERROR
COMMIT
Directs SQL*Plus to execute a COMMIT before exiting or continuing and save pending
changes to the database.
ROLLBACK
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 SQL*Plus to exit and return the SQL error
code if the SQL UPDATE command fails:
WHENEVER SQLERROR EXIT SQL.SQLCODE
UPDATE EMP_DETAILS_VIEW SET SALARY = SALARY*1.1;
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:
WHENEVER SQLERROR EXIT SQL.SQLCODE
column LAST_name headIing "Employee Name"
SHOW non_existed_option
The following PL/SQL block error causes SQL*Plus to exit and return the SQL error
code:
WHENEVER SQLERROR EXIT SQL.SQLCODE
begin
SELECT COLUMN_DOES_NOT_EXIST FROM DUAL;
END;
/
12-138
Chapter 12
XQUERY
12.54 XQUERY
Syntax
XQUERY xquery_statement
The SQL*Plus XQUERY command enables you to perform an XQuery 1.0 query on a
specified database. XQUERY is supported on Oracle Database 10g (Release 2) and
later versions. Attempting to use XQUERY on an earlier version of the Oracle
Database gives the error:
SP2-614 Server version too low
Terms
xquery_statement
Specifies the XQuery statement you want to run. The statement is entered with
standard XQuery syntax. The XQUERY statement is terminated with a forward slash,
'/'.
Usage
Prefix your XQuery statement with the SQL*Plus command, XQUERY, and terminate
the XQUERY command with a slash (/). XQUERY is a SQL*Plus keyword. If XQueries
are executed in other tools, the keyword may not be needed.
XML output from the XQUERY command is displayed as native XML according to the
active SET command options. SET LONG typically needs to be set. It may be useful to
consider the following settings:
• Linesize for rows longer than the default 80 characters (SET LINESIZE).
• LOB, LONG and XML Type Size for rows longer than the default 80 characters
(SET LONG).
• Output Page Setup to match output (SET PAGESIZE).
• Display Headings to repress the "Result Sequence" column heading (SET
HEADING OFF).
The XQUERY command requires an active database connection. The command will
not work with SQLPLUS /NOLOG.
Bind variables are not supported in the XQUERY command.
There are four SET commands specific to the XQUERY command. The SHOW
XQUERY command gives the status of these settings. They are:
• SET XQUERY BASEURI {text}
• SET XQUERY ORDERING {UNORDERED | ORDERED | DEFAULT}
• SET XQUERY NODE {BYVALUE | BYREFERENCE | DEFAULT}
• SET XQUERY CONTEXT {text}
12-139
Chapter 12
XQUERY
Examples
The XQuery statement in the following script queries the EMP_DETAILS_VIEW view
of the HR schema:
set long 160
set linesize 160
xquery for $i in fn:collection("oradb:/SCOTT/EMP_DETAILS_VIEW") return $i
/
Result Sequence
-------------------------------------------------------------------------------------
------
<ROW><EMPNO>7369</EMPNO><ENAME>SMITH</ENAME><JOB>CLERK</JOB><MGR>7902</
MGR><HIREDATE>17-
DEC-80</HIREDATE><SAL>800</SAL><DEPTNO>20</DEPTNO></ROW>
14 item(s) selected.
12-140
13
SQL*Plus Error Messages
This appendix lists error messages with prefixes SP2- and CPY- generated by
SQL*Plus:
• SQL*Plus Error Messages
• COPY Command Messages
For error messages with prefixes such as ORA-, TNS- and PLS- generated by Oracle
Database, see the Oracle Database Error Messages guide.
Action: Re-enter the ACCEPT command with a variable argument to store the input
value.
Action: Check the syntax of the ACCEPT command for the correct option.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
Action: Define a break. Check the syntax of the BREAK command for the correct
options.
Action: Check the syntax of the BREAK command for the correct options.
13-1
Chapter 13
SQL*Plus Error Messages
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
Action: Make sure the SQL buffer is not empty before using the CHANGE command.
Action: Check the syntax of the CHANGE command for the correct options.
Action: Make sure the SQL buffer is not empty before using the DEL command.
Action: Reduce the size of the SQL statement or PL/SQL block by one of the
following:
• Remove extra white space and comments.
• Re-code to use fewer commands and/or shorter variable names.
• Place sections of the block into stored (or packaged) procedures, and then call
these procedures from the block.
13-2
Chapter 13
SQL*Plus Error Messages
Action: Reduce the length of the data in the substitution variables used in the
command.
Action: Check the syntax of the command you used for the correct options.
SP2-0044 For a list of known commands enter HELP and to leave enter EXIT
Cause: An unknown command was entered.
Action: Check the syntax of the command you used for the correct options.
Action: Use the COLUMN command to make sure the column the format is based on
is defined first.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
13-3
Chapter 13
SQL*Plus Error Messages
Action: Define a COMPUTE. Check the syntax of the COMPUTE command for the
correct options.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
Action: Check the syntax of the command you used for the correct options, and use
the keyword in the appropriate place.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
13-4
Chapter 13
SQL*Plus Error Messages
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
Action: Enter a valid SQL command. SQL*Plus commands are not stored in the SQL
buffer.
Action: Enter a SQL command to save. SQL*Plus commands are not stored in the
SQL buffer.
Action: Check the following command syntax and enter a valid filename:
command filename[.ext] [CR[EATE]|REP[LACE]|AP[PEND]]
where command can be SAVE, SPOOL or STORE SET
To use the command keywords CREATE, REPLACE, APPEND or one of their
abbreviations as the filename, or to use the word FILE as the filename, you must
enclose it in single quotes.
13-5
Chapter 13
SQL*Plus Error Messages
Action: Check the syntax of the SAVE command for the correct options.
Action: Re-enter the DEFINE command with an assignment clause or a valid symbol
or variable name.
Action: UNDEFINE any unused variables to make room for this variable and re-run
the command.
13-6
Chapter 13
SQL*Plus Error Messages
Action: Note the message and number, and contact the System Administrator.
Action: Make a note of the message and the number, then contact the Database
Administrator.
Action: Check the syntax of the command you used for the correct options.
Action: Command-line SQL*Plus help is not installed in this Oracle instance. Use the
sqlplus/admin/help/hlpbld.sql script to install HELP on this database:
sqlplus system @hlpbld.sql helpus.sql
13-7
Chapter 13
SQL*Plus Error Messages
Action: Check the syntax of the command you used for the correct options.
Action: Check the syntax of the ACCEPT command for the correct options.
Action: Check that the line number is correct and try again.
Action: Check that the line number is correct and try again.
Action: Make sure the userid and password is correct and try again.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
13-8
Chapter 13
SQL*Plus Error Messages
Action: Check the syntax of the PRINT command for the correct options.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
Action: Increase the line size so that the item can be displayed.
Action: Check the syntax of the command you used for the correct options.
Action: Check the syntax of the command you used for the correct options.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
13-9
Chapter 13
SQL*Plus Error Messages
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
Action: Check the limits of the parameter and enter a value that is within the range.
Action: Make sure that the buffer variable name is correct and try again.
Action: Check the syntax of the command you used for the correct options.
Action: Check the syntax of the command you used for the correct options.
Action: Check the syntax of the command you used for the correct options.
13-10
Chapter 13
SQL*Plus Error Messages
Action: Retry the command with a valid string. Check the syntax of the command you
used for the correct options.
Action: Close the opening quotation mark with the corresponding closing quotation
mark.
Action: Check the syntax of the command you used for the correct options.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
Action: Check that timers were created with the TIMING command.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
13-11
Chapter 13
SQL*Plus Error Messages
Action: No action possible. SPOOL OUT has been disabled possibly because of lack
of printing support at the operating system level.
Action: Reduce the length in the substitution variable and try again.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
Action: Use the appropriate SQL*Plus command. See the documentation for a list of
commands and their correct syntax.
Action: Remove the command from the script. See the documentation for a list of
commands and their correct syntax.
13-12
Chapter 13
SQL*Plus Error Messages
Action: Correct and remove the illegal character from the buffer name.
Action: Check the syntax of the command you used for the correct options.
Action: Specify at least one clause. Check the syntax of the command you used for
the correct options.
Action: Check the syntax of the COPY command for the correct options.
Action: Check the syntax of the COPY command for the correct options.
Action: Check the syntax of the COPY command for the correct options.
Action: Check the syntax of the COPY command for the correct options.
Action: Check the syntax of the COPY command for the correct options.
Action: Check the syntax of the COPY command for the correct options.
13-13
Chapter 13
SQL*Plus Error Messages
Action: Check the syntax of the COPY command for the correct options.
Action: Specify the USING keyword before the USING clause of the COPY command.
Action: Include a FROM clause to specify a source database other than the default.
Action: Include a TO clause to specify a source database other than the default.
Action: Check the syntax of the COPY command for the correct options.
Action: Use the REPLACE option to overwrite the existing file, or specify another file
name.
Action: Ask your System Administrator why the Product User Profile (PUP) table has
been set to disable this command for your schema.
13-14
Chapter 13
SQL*Plus Error Messages
Action: Check the syntax of the SET command for the correct options.
Action: Enter a value within the SET option range and re-try the SET command.
Action: Check the syntax of the VARIABLE command for the correct usage.
Action: Check the syntax of the PRINT command for the correct usage.
Action: Check the syntax of the SHOW ERRORS command for the correct options.
Action: Run the VARIABLE command to check that the bind variables you used in
your SQL statement exist. Before running a SQL statement with bind variables, you
must use the VARIABLE command to declare each variable.
Action: Check the syntax of the EXECUTE command for the correct usage.
Action: Check the syntax of the DESCRIBE command for the correct usage.
13-15
Chapter 13
SQL*Plus Error Messages
Action: Check and make sure that the object name is correct.
Action: Remove the column specification in the DESCRIBE command and try again.
SP2-0575 Use of Oracle SQL feature not in SQL92 Entry |Intermediate|Full Level
Cause: A SQL statement was attempted that is not FIPS compliant. May also occur if
a SQL*Plus feature, for example SET AUTOTRACE, that uses Oracle-specific SQL
was turned on when you are using FIPS flagging.
Action: Use SET FLAGGER, and turn FIPS compliance checking OFF, or rewrite the
statement.
13-16
Chapter 13
SQL*Plus Error Messages
Action: Check the syntax of the EXIT command for the correct usage.
Action: Check the syntax of the COMPUTE command for the correct usage.
Action: Free up additional memory by: closing applications not required; reducing the
size of the command, or statement; or by recoding the query to select fewer records.
Action: Check the syntax of the COMPUTE command for the correct options.
Action: Check the syntax of the SET AUTOCOMMIT command for the correct options.
13-17
Chapter 13
SQL*Plus Error Messages
Action: Check the syntax of the SET EDITFILE command for the correct options.
Action: Check the syntax of the STORE command for the correct options.
SP2-0605 File file_name already exists. Use another name or STORE {SET}
filename[.ext] REPLACE
Cause: The file specified in the STORE command already exists.
Action: Use the REPLACE option to overwrite the existing file, or specify another file
name.
Action: Check that there is sufficient disk space and that the protection on the
directory enables file creation.
Action: Check that the file is not locked before closing it.
Action: Check the syntax of the SET AUTOTRACE command for the correct options.
Action: Free up additional memory by closing applications not required, or reduce the
size of the command, statement or query output.
Action: Make a note of the message and the number, then contact the Database
Administrator.
13-18
Chapter 13
SQL*Plus Error Messages
Action: Make sure the user has been granted the PLUSTRACE role, and that a
PLAN_TABLE has been created for the user.
Action: Check that AUTOTRACE is configured and that you have the PLUSTRACE
role enabled.
SP2-0618 Cannot find the Session Identifier. Check PLUSTRACE role is enabled
Error enabling autotrace_report report
Cause: Unable to find the session identifier.
Action: Check that the database limit on number of active sessions has not been
exceeded.
Action: Refer to the Oracle Database Error Messages for the specified ORA error
message.
SP2-0622 Starting line number must be less than ending line number
Cause: The starting line number specified is larger than the ending number.
Action: Re-enter the starting line number with a smaller line number.
13-19
Chapter 13
SQL*Plus Error Messages
Action: The exact format of the file extension and location of the file are system
dependent. See the SQL*Plus installation guide provided for your operating system.
The script must be run as user SYSTEM.
Action: Check that the specified variable is correct and try again.
Action: This package is created during the running of the CATPROC.SQL and should
be available on all databases from Oracle 7.2. Check that your database is correctly
installed.
Action: Reduce the size of the specified string and re-try the operation.
Action: Connect to the Oracle database before re-issuing the PASSWORD command.
Action: Make a note of the message, then contact Oracle Support Services.
Action: Check that the file was created successfully, and verify that the device you are
writing to is still available.
Action: Re-issue the PASSWORD command and make sure that the new passwords
are entered correctly.
13-20
Chapter 13
SQL*Plus Error Messages
Action: Re-issue the PASSWORD command and make sure that the new passwords
are entered correctly.
Action: Check the Oracle platform specific documentation to make sure SQL*Plus is
installed correctly. This may occur because the ORACLE_HOME environment
variable or registry equivalent is not set to the location of the Oracle software. Make
sure this value is set correctly. Check that the SQL*Plus binary message files exist in
the SQL*Plus message directory, for example $ORACLE_HOME/sqlplus/mesg.
Check the value of NLS_LANG environment variable or registry equivalent is correct.
Action: Make sure that the string only contains numeric digits.
Action: Make a note of the message and the number, then contact Oracle Support
Services.
13-21
Chapter 13
SQL*Plus Error Messages
Action: Rewrite the query to select the data with types that SQL*Plus supports.
Action: Check the syntax of the DESCRIBE command for the correct options.
Action: Check the syntax for the CONNECT command for the correct usage.
Action: Check the syntax of the STARTUP command for the correct usage.
Action: Check the syntax of the SHUTDOWN command for the correct usage.
Action: Check the syntax of the ARCHIVE LOG command for the correct usage.
Action: Check the syntax of the SHUTDOWN command for the correct options.
Action: Check the syntax of the ARCHIVE LOG command for the correct options.
13-22
Chapter 13
SQL*Plus Error Messages
Action: Check the syntax of the command you used for the correct options.
Action: Check the syntax of the command you used for the correct options.
Action: Reduce the length of the data in the substitution variables used in the
command.
Action: Check the syntax of the SET DESCRIBE command for the correct options.
Action: Ask your Database Administrator why SQL*Plus should be run with a -
RESTRICT option.
Action: Check the syntax of the SET SQLPLUSCOMPATIBLITY command for the
correct options.
13-23
Chapter 13
SQL*Plus Error Messages
Action: Make sure that the last synonym in the synonym path points to an object that
exists, and that it doesn't point back to itself.
Action: Make sure that all environment variables or registry entries needed to run
SQL*Plus are set. The variables are platform specific but may include
ORACLE_HOME, ORACLE_SID, NLS_LANG, and LD_LIBRARY_PATH.
On Windows if the environment variable called SQLPLUS is set, it must contain the
directory name of the SQL*Plus message files, for example ORACLE_HOME\sqlplus
\mesg.
Also check that the file sp1XX.msb is in the $ORACLE_HOME/sqlplus/mesg or
ORACLE_HOME\sqlplus\mesg directory. The "XX" stands for the country prefix
associated with your NLS_LANG environment variable. SQL*Plus reads only one of
the sp1XX.msb files. For example sp1ja.msb is read if NLS_LANG is
JAPANESE_JAPAN.JA16EUC. If NLS_LANG is not set, then the default (English
language) sp1us.msb is used. Check that the appropriate file is of non-zero size and
that the file permissions allow it to be read. Note that ".msb" files are binary. The
contents may be meaningless when viewed or printed. If you are unsure which
language file is being used, unset NLS_LANG and run SQL*Plus to verify it can read
the sp1us.msb file.
Action: Normally occurs after other errors showing that the database is not running, or
that the username and password were invalid.
Action: Check the syntax of the SQL*Plus executable for the correct options.
SP2-0753 STARTUP with MIGRATE only valid with Oracle 9.2 or greater
Cause: STARTUP MIGRATE was used to try to startup an Oracle server for a release
prior to 9.2.
Action: Check the platform specific environment to verify that you are connecting to an
Oracle server that is at least release 9.2.
13-24
Chapter 13
SQL*Plus Error Messages
Action: If quotes are used, check that they are correctly matched. Either quote the
whole argument, or quote the schema and object components separately.
Action: Check the syntax of the SPOOL command for the correct options.
Action: Check the syntax of the SPOOL command for the correct usage.
Action: Use the REPLACE option to overwrite the existing file, or specify another file
name.
13-25
Chapter 13
SQL*Plus Error Messages
Action:
Action:
Action:
Action:
Action: If a schema is specified, check that the schema and object names are
separated by a period.
Action: If the SHOW ERRORs argument is quoted, check that only double quotes are
used. Either quote the whole argument, or quote the schema and object components
separately.
Action: Reduce the length of the script name and path. Reduce the number and/or
size of the script arguments.
Action: Enter a valid number within a valid range for the datatype.
Action: Check the limits for the command option and enter a value within the allowed
range.
Action:
13-26
Chapter 13
SQL*Plus Error Messages
Action: Disconnect from the database instance before attempting to set the system
variable.
Action: Replace the invalid or incomplete string in the database with a valid or
complete string.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
13-27
Chapter 13
SQL*Plus Error Messages
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
13-28
Chapter 13
SQL*Plus Error Messages
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
13-29
Chapter 13
SQL*Plus Error Messages
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
13-30
Chapter 13
SQL*Plus Error Messages
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
13-31
Chapter 13
SQL*Plus Error Messages
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
13-32
Chapter 13
SQL*Plus Error Messages
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
Action: Use the SQL*Plus SHOW ERR[ORS] command to display the warnings and
messages.
SP2-1500 STARTUP with UPGRADE only valid with Oracle 9.2 or greater
Cause: STARTUP UPGRADE was used to try to startup an Oracle server for a
release prior to 9.2.
Action: Check the platform specific environment to verify that you are connecting to an
Oracle server that is at least release 9.2.
SP2-1501 STARTUP with DOWNGRADE only valid with Oracle 9.2 or greater
Cause: STARTUP DOWNGRADE was used to try to startup an Oracle server for a
release prior to 9.2.
Action: Check the platform specific environment to verify that you are connecting to an
Oracle server that is at least release 9.2.
Action: Check that the proxy setting has the correct value, or unset it if no proxy is
needed. SQL*Plus may get the proxy name from the environment variable http_proxy,
or the value may be set in another way on your system. Check that the given proxy
server is operational. Most web browsers can be configured to use a proxy. Configure
a browser to use the desired proxy and verify that web pages can still be loaded.
Action: Check that the Oracle environment or registry entries are consistent and
correct. If using the SQL*Plus Instant Client make sure the SQL*Plus and Oracle
libraries are from the same release. Make sure you have read access to the libraries.
Action: Check that the specified variable is initialized and try again.
13-33
Chapter 13
SQL*Plus Error Messages
Action: See elgsetup.txt in the sqlplus doc directory for information about how to
create a non-default error log table. See the Oracle Database Administrator's Guide
for information about how to grant privileges.
Action: Reenter the SET ERRORLOGGING OFF command without any other options.
Action: Reenter the SET ERRORLOGGING ON command with valid options. Valid
options are: TABLE, IDENTIFIER, and TRUNCATE.
Action: Reenter the SET ERRORLOGGING ON command with valid options. Valid
options are: TABLE, IDENTIFIER, and TRUNCATE.
Action: Reenter the SET ERRORLOGGING ON TABLE command with a valid table
name.
Action: Reenter the SET ERRORLOGGING ON TABLE command with a valid table
name.
Action: Reenter the SET ERRORLOGGING ON FILE command with a valid file name
and path.
13-34
Chapter 13
SQL*Plus Error Messages
Action: Check string quotes in the identifier before reentering the SET
ERRORLOGGING ON IDENTIFIER command.
Action: Check the privileges granted to access the error log table. See the Oracle
Database Administrator's Guide for information about how to grant privileges.
Action: See elgsetup.txt in the sqlplus doc directory for information about how to
create a non-default error log table.
Action: Check the privileges granted to access the error log table. See the Oracle
Database Administrator's Guide for information about how to grant privileges.
13-35
Chapter 13
COPY Command Messages
CPY-0004 Source and destination table and column names don't match
Cause: On an APPEND operation or an INSERT (when the table exists), at least one
column name in the destination table does not match the corresponding column name
in the optional column name list or in the SELECT command.
Action: Re-specify the COPY command, making sure that the column names and their
respective order in the destination table match the column names and column order in
the optional column list or in the SELECT command
Action: Re-specify the COPY command, making sure that the data types for items
being selected agree with the destination. Use TO_DATE, TO_CHAR, and
TO_NUMBER to make conversions.
Action: Re-specify the COPY command, making sure that the number of columns
being selected agrees with the number in the destination table.
13-36
Chapter 13
COPY Command Messages
Action: Re-specify the COPY command, making sure that the number of columns
being selected agrees with the number in the destination table.
CPY-0008 More column list names than columns in the destination table
Cause: On an APPEND operation or an INSERT (when the table exists), the number
of columns in the column name list is greater than the number of columns in the
destination table.
Action: Re-specify the COPY command, making sure that the number of columns in
the column list agrees with the number in the destination table.
CPY-0009 Fewer column list names than columns in the destination table
Cause: On an APPEND operation or an INSERT (when the table exists), the number
of columns in the column name list is less than the number of columns in the
destination table.
Action: Re-specify the COPY command, making sure that the number of columns in
the column list agrees with the number in the destination table.
Re-specify the COPY command, making sure that the unsupported datatype column
is removed. For more information, see the SQL*Plus COPY Command.
13-37
Part IV
SQL*Plus Appendixes
Part IV contains the following SQL*Plus appendixes:
• SQL*Plus Limits
• SQL*Plus COPY Command
• Obsolete SQL*Plus Commands
• SQL*Plus Instant Client
A
SQL*Plus Limits
The general SQL*Plus limits shown are valid for most operating systems.
Item Limit
filename length system dependent
username length 128 bytes
substitution variable name 128 bytes
length
substitution variable value 240 characters
length
command-line length 5000 characters
LONG 2,000,000,000 bytes
LINESIZE system dependent
LONGCHUNKSIZE value system dependent
output line size system dependent
SQL or PL/SQL command- 3,000 characters (internal only)
line size after variable
substitution
number of characters in a 500 characters
COMPUTE command label
number of lines per SQL 500 (assuming 80 characters per line)
command
maximum PAGESIZE 50,000 lines
total row width 32,767 characters
maximum ARRAYSIZE 5000 rows
maximum number of nested 20
scripts
maximum page number 99,999
maximum PL/SQL error 2K
message size
maximum ACCEPT 240 Bytes
character string length
maximum number of 2048
substitution variables
A-1
B
SQL*Plus COPY Command
This appendix discusses the following topics:
• COPY Command Syntax
• Copying Data from One Database to Another
• About Copying Data between Tables on One Database
Read this chapter while sitting at your computer and try out the example shown.
Before beginning, make sure you have access to the sample tables described in
SQL*Plus Quick Start .
The COPY command will be deprecated in future releases of SQL*Plus. After Oracle
9i, no new datatypes are supported by COPY.
Copies data from a query to a table in the same or another database. COPY supports
the following datatypes:
CHAR
DATE
LONG
NUMBER
VARCHAR2
WARNING:
Including your password in plain text is a security risk. You can avoid this risk
by omitting the password, and entering it only when the system prompts for it.
B.1.1 Terms
See the following list for a description of each term or clause:
FROM database
The database that contains the data to be copied. If you omit the FROM clause, the
source defaults to the database to which SQL*Plus is connected (that is, the database
that other commands address). You must use a FROM clause to specify a source
B-1
Appendix B
COPY Command Syntax
database other than the default. The COPY command FROM clause does not support
SYSDBA or SYSOPER privileged connections.
TO database
The database containing the destination table. If you omit the TO clause, the
destination defaults to the database to which SQL*Plus is connected (that is, the
database that other commands address). You must use a TO clause to specify a
destination database other than the default. The COPY command TO clause does not
support SYSDBA or SYSOPER privileged connections.
database
Inserts the rows from query into destination_table if the table exists. If
destination_table does not exist, COPY creates it.
CREATE
Inserts the rows from query into destination_table after first creating the table. If
destination_table already exists, COPY returns an error.
INSERT
Inserts the rows from query into destination_table. If destination_table does not exist,
COPY returns an error. When using INSERT, the USING query must select one
column for each column in destination_table.
REPLACE
Replaces destination_table and its contents with the rows from query. If
destination_table does not exist, COPY creates it. Otherwise, COPY drops the existing
table and replaces it with a table containing the copied data.
destination_table
Represents the table you wish to create or to which you wish to add data.
(column, column, column, ...)
Specifies the names of the columns in destination_table. You must enclose a name in
double quotes if it contains lowercase letters or blanks.
If you specify columns, the number of columns must equal the number of columns
selected by the query. If you do not specify any columns, the copied columns will have
the same names in the destination table as they had in the source if COPY creates
destination_table.
B-2
Appendix B
Copying Data from One Database to Another
USING query
Specifies a SQL query (SELECT command) determining which rows and columns
COPY copies.
B.1.2 Usage
To enable the copying of data between Oracle and non-Oracle databases, NUMBER
columns are changed to DECIMAL columns in the destination table. Hence, if you are
copying between Oracle databases, a NUMBER column with no precision will be
changed to a DECIMAL(38) column. When copying between Oracle databases, you
should use SQL commands (CREATE TABLE AS and INSERT) or you should ensure
that your columns have a precision specified.
The SQL*Plus SET LONG variable limits the length of LONG columns that you copy. If
any LONG columns contain data longer than the value of LONG, COPY truncates the
data.
SQL*Plus performs a commit at the end of each successful COPY. If you set the
SQL*Plus SET COPYCOMMIT variable to a positive value n, SQL*Plus performs a
commit after copying every n batches of records. The SQL*Plus SET ARRAYSIZE
variable determines the size of a batch.
Some operating environments require that service names be placed in double quotes.
B.1.3 Examples
The following command copies the entire EMPLOYEES table to a table named
WESTEMPLOYEES. Note that the tables are located in two different databases. If
WESTEMPLOYEES already exists, SQL*Plus replaces the table and its contents. The
columns in WESTEMPLOYEES have the same names as the columns in the source
table, EMPLOYEES.
COPY FROM HR@HQ TO JOHN@WEST -
REPLACE WESTEMPLOYEES -
USING SELECT * FROM EMPLOYEES
The following command copies selected records from EMPLOYEES to the database to
which SQL*Plus is connected. SQL*Plus creates SALESMEN through the copy.
SQL*Plus copies only the columns EMPLOYEE_ID and LAST_NAME, and at the
destination names them EMPLOYEE_ID and SA_MAN.
COPY FROM HR@ORACLE01 -
CREATE SALESMEN (EMPLOYEE_ID, SA_MAN) -
USING SELECT EMPLOYEE_ID, LAST_NAME FROM EMPLOYEES -
WHERE JOB_ID='SA_MAN';
B-3
Appendix B
Copying Data from One Database to Another
• Copy data from one remote database to another remote database (most systems).
Note:
In general, the COPY command was designed to be used for copying data
between Oracle and non-Oracle databases. You should use SQL commands
(CREATE TABLE AS and INSERT) to copy data between Oracle databases.
To specify a database in the FROM or TO clause, you must have a valid username
and password for the local and remote databases and know the appropriate Oracle
Net service names. COPY obeys Oracle Database security, so the username you
specify must have been granted access to tables for you to have access to tables. For
information on what databases are available to you, contact your DBA.
When you copy to your local database from a remote database, you can omit the TO
clause. When you copy to a remote database from your local database, you can omit
the FROM clause. When you copy between remote databases, you must include both
clauses. However, including both clauses increases the readability of your scripts.
The COPY command behaves differently based on whether the destination table
already exists and on the action clause you enter (CREATE in the example). See
About Controlling Treatment of the Destination Table for more information.
By default, the copied columns have the same names in the destination table that they
have in the source table. If you want to give new names to the columns in the
destination table, enter the new names in parentheses after the destination table
name. If you enter any column names, you must enter a name for every column you
are copying.
B-4
Appendix B
Copying Data from One Database to Another
Note:
To enable the copying of data between Oracle and non-Oracle databases,
NUMBER columns are changed to DECIMAL columns in the destination table.
Hence, if you are copying between Oracle databases, a NUMBER column with
no precision will be changed to a DECIMAL(38) column. When copying
between Oracle databases, you should use SQL commands (CREATE TABLE
AS and INSERT) or you should ensure that your columns have a precision
specified.
The USING clause specifies a query that names the source table and specifies the
data that COPY copies to the destination table. You can use any form of the SQL
SELECT command to select the data that the COPY command copies.
Here is an example of a COPY command that copies only two columns from the
source table, and copies only those rows in which the value of DEPARTMENT_ID is
30:
COPY FROM HR@BOSTONDB -
REPLACE EMPCOPY2 -
USING SELECT LAST_NAME, SALARY -
FROM EMP_DETAILS_VIEW -
WHERE DEPARTMENT_ID = 30
You may find it easier to enter and edit long COPY commands in scripts rather than
trying to enter them directly at the command prompt.
B-5
Appendix B
Copying Data from One Database to Another
Use APPEND when you want to insert data in an existing table, or create a new table
if the destination table does not exist. APPEND specifies the following actions:
• If the destination table already exists, COPY inserts the copied data in the
destination table.
• If the table does not already exist, COPY creates the table and then inserts the
copied data in it.
Note:
See your DBA for an appropriate username, password, and service name for a
remote computer that contains a copy of EMPLOYEE_COPY.
SQL*Plus then creates the table EMPLOYEE_COPY and copies the rows:
Table SALESMAN created.
In this COPY command, the FROM clause directs COPY to connect you to the
database with the specification BOSTONDB as HR.
Notice that you do not need a semicolon at the end of the command; COPY is a
SQL*Plus command, not a SQL command, even though it contains a query. Since
most COPY commands are longer than one line, you must use a line continuation
hyphen (-), optionally preceded by a space, at the end of each line except the last.
Example B-1 Copying from a Remote Database to Your Local Database Using
CREATE
To copy HR from a remote database into a table called EMPLOYEE_COPY on your
own database, enter the following command:
B-6
Appendix B
About Copying Data between Tables on One Database
batches are copied.) For more information on SET variables, including how to change
their settings, see the SET command.
After listing the three system variables and their values, COPY tells you if a table was
dropped, created, or updated during the copy. Then COPY lists the number of rows
selected, inserted, and committed.
Of course, you could get the same result by instructing COPY to log in to the remote
database as ADAMS. You cannot do that, however, unless you know the password
associated with the username ADAMS.
To copy between tables on a remote database, include the same username and
service name in the FROM and TO clauses:
COPY FROM HR@BOSTONDB -
TO HR@BOSTONDB -
INSERT EMPLOYEE_COPY2 -
USING SELECT * FROM EMPLOYEE_COPY
B-7
C
Obsolete SQL*Plus Commands
This appendix covers earlier versions of some SQL*Plus commands. While these
older commands still function in SQL*Plus, they are not supported. It is recommended
that you use the alternative SQL*Plus commands listed in the following table.
Obsolete
SET CLOSECURSOR none
Obsolete
SET DOCUMENT none
Obsolete
SET MAXDATA none
C-1
Appendix C
BTI[TLE] text (obsolete old form)
C-2
Appendix C
SET COM[PATIBILITY]{V7 | V8 | NATIVE} (obsolete)
If the buffer name you enter does not exist, SET BUFFER defines (creates and
names) the buffer. SQL*Plus deletes the buffer and its contents when you exit
SQL*Plus.
Running a query automatically makes the SQL buffer the current buffer. To copy text
from one buffer to another, use the GET and SAVE commands. To clear text from the
current buffer, use CLEAR BUFFER. To clear text from the SQL buffer while using a
different buffer, use CLEAR SQL.
Example
To run a script, SALARY.SQL, created with Oracle7 SQL syntax, enter
SET COMPATIBILITY V7
START SALARY
After running the file, reset compatibility to NATIVE to run scripts created for Oracle
Database 10g:
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.
C-3
Appendix C
SET MAXD[ATA] n (obsolete)
C-4
Appendix C
TTI[TLE] text (obsolete old form)
This formatting string will print the word "page" with an initial capital letter and format
the page number to a width of two. You can substitute any text for "page" and any
number for the width. You must set escape so that SQL*Plus does not interpret the
ampersand (&) as a substitution variable. See SET ERRORL[OGGING] {ON | OFF}
[TABLE [schema.]tablename] [TRUNCATE] [IDENTIFIER identifier] for more
information on setting the escape character.
SQL*Plus interprets TTITLE in the old form if a valid new-form clause does not
immediately follow the command name.
If you want to use CENTER with TTITLE and put more than one word on a line, you
should use the new form of TTITLE. For more information see the TTITLE command.
Example
To use the old form of TTITLE to set a top title with a left-aligned date and right-
aligned page number on one line followed by SALES DEPARTMENT on the next line
and PERSONNEL REPORT on a third line, enter
TTITLE 'SALES DEPARTMENT|PERSONNEL REPORT'
C-5
D
SQL*Plus Instant Client
SQL*Plus Instant Client is a standalone product with all the functionality of SQL*Plus
command-line. It connects to existing remote Oracle databases, but does not include
its own database. It is easy to install and uses significantly less disk space than the full
Oracle Database Client installation required to use SQL*Plus command-line.
SQL*Plus Instant Client is available on platforms that support the OCI Instant Client.
See About OCI Instant Client for more information on the OCI Instant Client.
To install SQL*Plus Instant Client, you need two packages:
• SQL*Plus Instant Client package.
• Either the Basic OCI Instant Client package, or the lightweight OCI Instant Client
package.
D-1
Appendix D
About Installing SQL*Plus Instant Client by Downloading from OTN
– WE8MSWIN1252
– WE8ISO8859P1
– UTF8
– AL16UTF16
– AL32UTF8
For example:
NLS_LANG=AMERICAN_AMERICA.UTF8
2. Use rpm -i for the initial install of the RPM packages, or rpm -u to upgrade to a
newer version of the packages.
D.2.2 Installing SQL*Plus Instant Client from the UNIX or Windows Zip
Files
1. Download the zip files containing the SQL*Plus Instant Client package, and the
OCI package from the OTN Instant Client page at http://www.oracle.com/
D-2
Appendix D
About Installing SQL*Plus Instant Client by Downloading from OTN
D-3
Appendix D
Installing SQL*Plus Instant Client from the 12c Client Release Media
3. Copy the SQL*Plus Instant Client and the OCI Instant Client files to the new
directory. All files must be copied from the same ORACLE_HOME.
See Installing SQL*Plus Instant Client on UNIX or Linux or Installing SQL*Plus
Instant Client on Windows for a list of the files to copy.
4. Configure SQL*Plus Instant Client. See About Configuring SQL*Plus Instant
Client.
To install SQL*Plus Instant Client using the lightweight OCI package on UNIX and
Linux, copy the following files:
$ORACLE_HOME/instantclient/light/libociicus.so
$ORACLE_HOME/lib/libclntsh.so.12.1
$ORACLE_HOME/lib/libnnz12.so
$ORACLE_HOME/lib/libsqlplus.so
$ORACLE_HOME/lib/libsqlplusic.so
$ORACLE_HOME/bin/sqlplus
To install SQL*Plus Instant Client using the lightweight OCI package on Windows,
copy the following files:
D-4
Appendix D
About Configuring SQL*Plus Instant Client
ORACLE_HOME\instantclient\light\oraociicus12.dll
ORACLE_HOME\bin\oci.dll
ORACLE_HOME\bin\orannzsbb12.dll
ORACLE_HOME\bin\orasqlplusic12.dll
ORACLE_HOME\bin\sqlplus.exe
If you install multiple versions of SQL*Plus, you may need to change the symbolic
link /usr/bin/sqlplus to the version of SQL*Plus matching the libraries in
LD_LIBRARY_PATH. For 12.2.0.1, /usr/bin/sqlplus is a symbolic link to the
SQL*Plus binary at /usr/lib/oracle/12.1.0.1/client/bin/sqlplus.
3. Set Oracle globalization variables required for your locale. A default locale will be
assumed if no variables are set. See Locale Datafor more information.
For example:
NLS_LANG=AMERICAN_AMERICA.UTF8
export NLS_LANG
D-5
Appendix D
About Connecting to a Database with SQL*Plus Instant Client
LD_LIBRARY_PATH=/home/instantclient12_2:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
2. Add the directory containing the Instant Client files to the PATH environment
variable. If it is not set, then an absolute or relative path must be used to start
SQL*Plus. Remove any other Oracle directories from PATH. For example:
PATH=/home/instantclient12_2:${PATH}
export PATH
3. Set Oracle globalization variables required for your locale. A default locale will be
assumed if no variables are set. See Locale Datafor more information.
For example:
NLS_LANG=AMERICAN_AMERICA.UTF8
export NLS_LANG
Net Service Names can be stored in a number of places, including LDAP. The use of
LDAP is recommended to take advantage of the new features of Oracle Database 12c.
See Local Naming Parameters in the tnsnames.ora Filefor more information.
D-6
Appendix D
AS SYSDBA or AS SYSOPER Connections with SQL*Plus Instant Client
If you want to use Net Service Names configured in a local Oracle Net tnsnames.ora
file, then set the environment variable TNS_ADMIN to the directory containing the
tnsnames.ora file. For example, on UNIX, if your tnsnames.ora file is in /home/user1
and it defines the Net Service Name MYDB2:
TNS_ADMIN=/home/user1
export TNS_ADMIN
sqlplus hr@MYDB2
The TWO_TASK (on UNIX) or LOCAL (on Windows) environment variable can be set
to a connection identifier. This removes the need to explicitly enter the connection
identifier whenever a connection is made in SQL*Plus or SQL*Plus Instant Client. This
UNIX example connects to the database known as MYDB4:
TNS_ADMIN=/home/user1
export TNS_ADMIN
TWO_TASK=MYDB4
export TWO_TASK
sqlplus hr
On Windows, TNS_ADMIN and LOCAL may be set in the System Properties. See
Configuring SQL*Plus Instant Client on Windows.
D-7
Appendix D
About Uninstalling Instant Client
D-8
Index
Symbols @ (at sign) (continued)
command, 2-6, 5-10, 12-4
_CONNECT_IDENTIFIER predefined variable, command arguments, 12-4, 12-6
2-5, 12-35, 12-36 in CONNECT command, 12-32
_DATE predefined variable, 12-35, 12-36 in COPY command, B-1, B-4
_EDITOR predefined variable, 5-1, 12-35, 12-36, in SQLPLUS command, 3-6
12-46 passing parameters to a script, 12-4, 12-6
_EDITOR substitution variable, 12-36 script, 5-10, 12-4
_EDITOR, in EDIT command, 5-1, 12-37, 12-46 similar to START, 5-10, 12-120
_O_RELEASE predefined variable, 12-35, 12-36 @ at sign)
_O_VERSION predefined variable, 12-35, 12-36 similar to START, 12-4
_PRIVILEGE predefined variable, 12-35, 12-36 @@ (double at sign) command, 2-6, 12-5
_RC predefined variable, 12-53 script, 12-6
_SQLPLUS_RELEASE predefined variable, similar to START, 12-5, 12-120
12-35, 12-36, 12-38 * (asterisk)
_USER predefined variable, 12-35, 12-36 in DEL command, 5-3, 12-38
-~ negative infinity sign, 12-24 in LIST command, 5-3, 12-55
-AC option, 3-13 /*...*/ (comment delimiters), 5-8
-MARKUP, 3-8, 7-1 # pound sign
SQLPLUS command clause, 3-9, 12-94 overflow indication, 12-24
-SILENT option, 3-13, 7-6 SET SQLPREFIX character, 12-105
; (semicolon), 4-3, 5-3, 12-55 ~ infinity sign, 12-24
((amp)) (ampersand) $ number format, 6-4
disabling substitution variables, 5-17
substitution variables, 5-13
((amp))((amp)), 5-14
Numerics
((colon)) (colon) 0, number format, 6-4
bind variables, 5-21 9, number format, 6-4
((colon))BindVariable clause
EXIT command, 12-48
((nbsp))- (hyphen) A
clause, 3-7 ABORT mode, 12-117
continuing a long SQL*Plus command, 4-7, abort query, 4-8
12-1 ACCEPT command, 5-19, 12-7
((nbsp))-- (comment delimiter), 5-8 and DEFINE command, 12-34
((nbsp)). (period), 4-5 BINARY_DOUBLE clause, 12-8, 12-132
((nbsp))/ (slash) command BINARY_FLOAT clause, 12-8, 12-132
default logon, 3-14, 12-33 customizing prompts for value, 5-19
entered at buffer line-number prompt, 4-5, DATE clause, 12-8
12-7 DEFAULT clause, 12-8
entered at command prompt, 12-7 FORMAT clause, 12-8
executing current PL/SQL block, 4-5 HIDE clause, 12-8
similar to RUN, 12-7, 12-69 NOPROMPT clause, 12-8
usage, 12-7 NUMBER clause, 5-20
@ (at sign) PROMPT clause, 5-19, 12-8
Index-1
Index
Index-2
Index
3
Index
Index-4
Index
5
Index
Index-6
Index
7
Index
F glogin (continued)
See also login.sql
FAILURE clause, 12-47 GRANT command, 9-1
FEEDBACK variable, 12-73, 12-88
file extensions, 2-6, 12-71, 12-107, 12-126 H
file names
in @ (at sign) command, 12-4 HEAD clause, 3-9
in @@ (double at sign) command, 12-6 HEAD option, 3-9
in EDIT command, 12-45 headers
in GET command, 12-49 aligning elements, 6-19
in SAVE command, 12-70 displaying at top of page, 12-67
in SPOOL command, 6-26, 12-118 displaying system-maintained values, 12-68
in SQLPLUS command, 3-14 setting at the start of reports, 6-18
files suppressing, 6-19
flat, 6-26 HEADING clause, 6-1, 12-24
required for SQL*Plus Instant Client, D-3 HEADING variable, 12-89
FLAGGER variable, 12-73, 12-89 headings
flat file, 6-26 aligning elements, 12-68
FLUSH variable, 8-9, 12-73, 12-89 column headings, 12-89
FOLD_AFTER clause, 12-21 formatting elements, 12-68
FOLD_BEFORE clause, 12-21 indenting, 12-68
font listing current definition, 12-67
changing face and size in command-line, 1-1 suppressing definition, 12-68
footers HEADSEP variable, 12-73, 12-90
aligning elements, 12-68 use in COLUMN command, 6-2
displaying at bottom of page, 12-66 help
displaying system-maintained values, 12-68 installing command-line, 2-7
formatting elements, 12-68 online, 3-6, 12-49
indenting, 12-68 HELP command, ? command, 12-49
listing current definition, 12-66 HIDE clause, 12-8
setting at the end of reports, 6-18 HISTORY clause, 12-112
suppressing definition, 12-68 HISTORY command, 12-50
FORCE clause, 12-122 CLEAR clause, 12-51
FORMAT clause, 12-8, 12-21 EDIT clause, 12-51
in ATTRIBUTE command, 12-11 DEL[ETE] clause, 12-51
in COLUMN command, 6-3, 6-5 LIST clause, 12-51
in REPHEADER and REPFOOTER RUN clause, 12-51
commands, 12-68 HISTORY variable, 12-73
in TTITLE and BTITLE commands, 6-21, HOST command, 4-9, 12-53
12-128 HTML, 7-2
format models, number, 6-3, 12-23 clause, 3-9
formfeed, to begin a new page, 6-24, 12-97 entities, 7-5
FROM clause, 12-60, B-4 option, 3-9
spooling to file, 3-11
G tag, 7-1
hyphen
GET command, 12-49 continuing a long SQL*Plus command, 4-7,
LIST clause, 12-49 12-1
NOLIST clause, 12-49
retrieving scripts, 12-49 I
globalization support,
Oracle10g, 11-3 IMMEDIATE mode, 12-117
glogin, 2-4 infinity sign (~), 12-24
profile, 12-105 INIT.ORA file
site profile, 2-4, 2-5, 3-13, 12-104 parameter file, 12-122
Index-8
Index
9
Index
M NONE clause
WHENEVER OSERROR, 12-137
MARKUP, 3-8, 7-1, 12-94, 12-96 WHENEVER SQLERROR, 12-138
BODY clause, 3-9 NOPARALLEL clause, 12-62
DELIMITER clause, 12-94 NOPRINT clause, 6-13, 6-23, 8-8, 12-25
ENTMAP clause, 3-10 NOPROMPT clause, 12-8
HEAD clause, 3-9 NORMAL mode, 12-117
PREFORMAT clause, 3-11 Notepad on Windows, 12-36
QUOTE clause, 12-94 NULL clause, 12-25
TABLE clause, 3-10 null values
MAXDATA variable, C-1, C-4 setting text displayed, 12-25, 12-73, 12-98
media recovery, 12-123 NULL variable, 12-73, 12-98
message, sending to screen, 5-19, 12-58 NUMBER
MOUNT clause, 12-122 column definition from DESCRIBE, 12-40
mounting a database, 12-122 NUMBER clause, 5-20
VARIABLE command, 12-130
NUMBER columns
N changing format, 6-3, 12-22
national language support, 11-1 default format, 6-3, 12-23
See also globalization support number formats
NCHAR clause $, 6-4
VARIABLE command, 12-130 0, 6-4
NCHAR columns 9, 6-4
changing format, 12-21 comma, 6-4
default format, 6-5, 12-21 setting default, 5-17, 12-74, 12-98
NCLOB clause NUMFORMAT clause
VARIABLE command, 12-132 in LOGIN.SQL, 2-6
NCLOB columns NUMFORMAT variable, 12-74, 12-98
changing format, 12-21 NUMWIDTH variable, 12-74, 12-98
default format, 12-21 effect on NUMBER column format, 6-3,
setting maximum width, 12-73, 12-92 12-23
setting retrieval position, 12-73, 12-91 NVARCHAR2 columns
setting retrieval size, 8-9, 12-73, 12-93 changing format, 12-21
negative infinity sign (-~), 12-24 default format, 6-5, 12-21
net service name, 3-3
NEW_VALUE clause, 6-23, 12-24
storing current date in variable for titles,
O
12-24 objects, describing, 12-81
NEWLINE clause, 12-24 obsolete commands
NEWPAGE command, C-1, C-2 BTITLE, C-2
NEWPAGE variable, 6-24, 12-73, 12-97 COLUMN command DEFAULT clause, C-2
NLS, 11-1 DOCUMENT, C-1, C-2
NLS_DATE_FORMAT, 12-8, 12-27 NEWPAGE, C-1, C-2
NLS_LANG SET command BUFFER variable, C-2
charset parameter for Instant Client, D-1 SET command CLOSECURSOR variable,
environment variables, 2-1 C-1, C-3
language parameter for Instant Client, D-1 SET command COMPATIBILITY variable,
SQL*Plus Instant Client, D-1 C-1, C-3
territory parameter for Instant Client, D-1 SET command DOCUMENT variable, C-1,
NODE variable, 12-75 C-3
NODE XQUERY option, 12-110 SET command MAXDATA variable, C-1, C-4
NOLIST clause, 12-49 SET command SCAN variable, C-1, C-4
NOLOG, 3-4, 3-14 SET command SPACE variable, C-1, C-4
nolongontime, 3-12 SET command TRUNCATE variable, C-1,
NOMOUNT clause, 12-123 C-4
Index-10
Index
11
Index
Index-12
Index
13
Index
Index-14
Index
15
Index
Index-16
Index
17
Index
Index-18
Index
19