SQL Plus User Guide
SQL Plus User Guide
December 2003
SQL*Plus User’s Guide and Reference, Release 10.1
Contributor: Alison Goggin, Alison Holloway, Christopher Jones, Luan Nim, Richard Rendell, Andrei
Souleimanian, Ian Wu.
The Programs (which include both the software and documentation) contain proprietary information;
they are provided under a license agreement containing restrictions on use and disclosure and are also
protected by copyright, patent, and other intellectual and industrial property laws. Reverse engineering,
disassembly, or decompilation of the Programs, except to the extent required to obtain interoperability
with other independently created software or as specified by law, is prohibited.
The information contained in this document is subject to change without notice. If you find any problems
in the documentation, please report them to us in writing. This document is not warranted to be
error-free. Except as may be expressly permitted in your license agreement for these Programs, no part of
these Programs may be reproduced or transmitted in any form or by any means, electronic or
mechanical, for any purpose.
If the Programs are delivered to the United States Government or anyone licensing or using the
Programs on behalf of the United States Government, the following notice is applicable:
U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical
data delivered to U.S. Government customers are "commercial computer software" or "commercial
technical data" pursuant to the applicable Federal Acquisition Regulation and agency-specific
supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the
Programs, including documentation and technical data, shall be subject to the licensing restrictions set
forth in the applicable Oracle license agreement, and, to the extent applicable, the additional rights set
forth in FAR 52.227-19, Commercial Computer Software--Restricted Rights (June 1987). Oracle
Corporation, 500 Oracle Parkway, Redwood City, CA 94065
The Programs are not intended for use in any nuclear, aviation, mass transit, medical, or other inherently
dangerous applications. It shall be the licensee's responsibility to take all appropriate fail-safe, backup,
redundancy and other measures to ensure the safe use of such applications if the Programs are used for
such purposes, and we disclaim liability for any damages caused by such use of the Programs.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be
trademarks of their respective owners.
The Programs may provide links to Web sites and access to content, products, and services from third
parties. Oracle is not responsible for the availability of, or any content provided on, third-party Web
sites. You bear all risks associated with the use of such content. If you choose to purchase any products
or services from a third party, the relationship is directly between you and the third party. Oracle is not
responsible for: (a) the quality of third-party products or services; or (b) fulfilling any of the terms of the
agreement with the third party, including delivery of products or services and warranty obligations
related to purchased products or services. Oracle is not responsible for any loss or damage of any sort
that you may incur from dealing with any third party.
Contents
Preface.......................................................................................................................................................... xix
Intended Audience ............................................................................................................................... xx
Documentation Accessibility .............................................................................................................. xx
Structure ................................................................................................................................................ xxi
Related Documents............................................................................................................................. xxiii
Conventions........................................................................................................................................ xxiv
iii
Part I SQL*Plus Getting Started
1 SQL*Plus Overview
What is SQL*Plus................................................................................................................................ 1-1
SQL*Plus Command-line and Windows GUI Architecture....................................................... 1-2
SQL*Plus Client............................................................................................................................. 1-2
Oracle Database ............................................................................................................................ 1-2
iSQL*Plus Architecture...................................................................................................................... 1-2
Web Browser ................................................................................................................................. 1-3
Application Server ........................................................................................................................ 1-3
Oracle Database ............................................................................................................................ 1-3
SQL*Plus Installation ........................................................................................................................ 1-4
SQL*Plus Date Format ................................................................................................................. 1-4
Who Can Use SQL*Plus..................................................................................................................... 1-4
How Can I Learn SQL*Plus .............................................................................................................. 1-5
How to Use the SQL*Plus Guide ..................................................................................................... 1-5
Oracle Database Sample Schemas and SQL*Plus ........................................................................ 1-5
Unlocking the Sample Tables...................................................................................................... 1-6
iv
iSQL*Plus History Screen .......................................................................................................... 2-18
iSQL*Plus Input Required Screen ............................................................................................ 2-19
iSQL*Plus Preferences Screen ................................................................................................... 2-20
Preferences and Equivalent SET Commands.............................................................................. 2-25
3 Configuring SQL*Plus
SQL*Plus and iSQL*Plus Environment Variables....................................................................... 3-1
SQL*Plus and iSQL*Plus Configuration ....................................................................................... 3-4
Site Profile ...................................................................................................................................... 3-6
User Profile .................................................................................................................................... 3-7
Storing and Restoring SQL*Plus System Variables ................................................................. 3-8
Installing Command-line Help................................................................................................. 3-10
Configuring Oracle Net Services.............................................................................................. 3-12
iSQL*Plus Application Server Configuration ............................................................................ 3-12
Changing the iSQL*Plus Application Server Port in Use ..................................................... 3-12
Testing if the iSQL*Plus Application Server is Running ...................................................... 3-14
Setting the Level of iSQL*Plus Logging .................................................................................. 3-15
Setting the Session Time Out .................................................................................................... 3-15
Enabling or Disabling Restricted Database Access ............................................................... 3-16
Enabling iSQL*Plus DBA Access.............................................................................................. 3-17
Enabling SSL with iSQL*Plus ................................................................................................... 3-21
Enabling or Disabling iSQL*Plus or iSQL*Plus Help............................................................ 3-24
Enabling User Defined HTML Markup .................................................................................. 3-24
iSQL*Plus Web Browser Configuration ...................................................................................... 3-25
Session Integrity.......................................................................................................................... 3-25
Retained Session Settings .......................................................................................................... 3-26
Windows Graphical User Interface Configuration.................................................................... 3-26
Setting Options and Values Using the Environment Dialog ............................................... 3-26
Customizing Registry Entries that affect SQL*Plus on Windows....................................... 3-28
4 Starting SQL*Plus
Login Username and Password........................................................................................................ 4-1
Changing your Password ............................................................................................................ 4-2
Changing Your Password in iSQL*Plus .................................................................................... 4-2
Expired Password......................................................................................................................... 4-4
v
Expired Password Screen in iSQL*Plus..................................................................................... 4-4
Connecting to a Database .................................................................................................................. 4-4
Net Service Name ......................................................................................................................... 4-5
Full Connection Identifier ........................................................................................................... 4-6
Easy Connection Identifier .......................................................................................................... 4-6
Connectionless Session with /NOLOG..................................................................................... 4-6
Starting SQL*Plus............................................................................................................................... 4-7
Starting Command-line SQL*Plus.............................................................................................. 4-8
Getting Command-line Help ...................................................................................................... 4-9
Starting the Windows Graphical User Interface ...................................................................... 4-9
Starting the iSQL*Plus Application Server ............................................................................. 4-11
To Check the HTTP Port used by the iSQL*Plus Application Server ................................. 4-12
Stopping the iSQL*Plus Application Server ........................................................................... 4-13
Running iSQL*Plus..................................................................................................................... 4-13
Running iSQL*Plus as a DBA ................................................................................................... 4-14
Starting iSQL*Plus from a URL ................................................................................................ 4-14
Getting Help in iSQL*Plus......................................................................................................... 4-16
Exiting SQL*Plus .............................................................................................................................. 4-16
Exiting the Command-line User Interface .............................................................................. 4-17
Exiting the Windows Graphical User Interface...................................................................... 4-17
Exiting the iSQL*Plus User Interface ....................................................................................... 4-17
SQLPLUS Program Syntax.............................................................................................................. 4-18
Options ......................................................................................................................................... 4-18
Logon ............................................................................................................................................ 4-24
Start ............................................................................................................................................... 4-25
5 SQL*Plus Basics
Entering and Executing Commands ................................................................................................ 5-2
The SQL Buffer.............................................................................................................................. 5-3
Executing Commands .................................................................................................................. 5-3
Listing a Table Definition ................................................................................................................. 5-4
Listing PL/SQL Definitions .............................................................................................................. 5-5
Running SQL Commands ................................................................................................................. 5-5
vi
Understanding SQL Command Syntax..................................................................................... 5-6
Running PL/SQL Blocks.................................................................................................................... 5-8
Creating Stored Procedures ........................................................................................................ 5-9
Running SQL*Plus Commands ..................................................................................................... 5-10
Understanding SQL*Plus Command Syntax ......................................................................... 5-11
System Variables that Affect How Commands Run ................................................................. 5-12
Stopping a Command while it is Running .................................................................................. 5-12
Running Operating System Commands ...................................................................................... 5-13
Pausing the Display ......................................................................................................................... 5-13
Saving Changes to the Database Automatically......................................................................... 5-13
Interpreting Error Messages ........................................................................................................... 5-15
vii
Restrictions ................................................................................................................................. 6-23
System Variables and iSQL*Plus Preferences......................................................................... 6-23
Substitution Variables in iSQL*Plus ............................................................................................ 6-24
iSQL*Plus Input Required Screen ............................................................................................ 6-25
Passing Parameters through the START Command .................................................................. 6-26
Communicating with the User ....................................................................................................... 6-28
Receiving a Substitution Variable Value ............................................................................... 6-28
Customizing Prompts for Substitution Variable ................................................................... 6-29
Sending a Message and Accepting Return as Input .............................................................. 6-31
Clearing the Screen ..................................................................................................................... 6-31
Using Bind Variables ....................................................................................................................... 6-32
Creating Bind Variables ............................................................................................................. 6-32
Referencing Bind Variables ....................................................................................................... 6-32
Displaying Bind Variables......................................................................................................... 6-33
Using REFCURSOR Bind Variables ............................................................................................. 6-33
viii
Defining Page and Report Titles and Dimensions .................................................................... 7-24
Setting the Top and Bottom Titles and Headers and Footers .............................................. 7-24
Displaying System-Maintained Values in Titles.................................................................... 7-29
Listing, Suppressing, and Restoring Page Title Definitions................................................. 7-30
Displaying Column Values in Titles ........................................................................................ 7-31
Displaying the Current Date in Titles...................................................................................... 7-32
Setting Page Dimensions ........................................................................................................... 7-33
Storing and Printing Query Results.............................................................................................. 7-35
Creating a Flat File...................................................................................................................... 7-35
Sending Results to a File............................................................................................................ 7-36
Sending Results to a Printer ...................................................................................................... 7-36
9 Tuning SQL*Plus
Tracing Statements ............................................................................................................................. 9-1
Controlling the Autotrace Report .............................................................................................. 9-2
Execution Plan............................................................................................................................... 9-4
Statistics.......................................................................................................................................... 9-4
Collecting Timing Statistics ............................................................................................................. 9-8
Tracing Parallel and Distributed Queries...................................................................................... 9-8
SQL*Plus Script Tuning .................................................................................................................. 9-11
COLUMN NOPRINT................................................................................................................. 9-12
SET APPINFO OFF..................................................................................................................... 9-12
SET ARRAYSIZE ........................................................................................................................ 9-12
SET DEFINE OFF........................................................................................................................ 9-12
SET FLUSH OFF ......................................................................................................................... 9-12
SET LINESIZE ............................................................................................................................. 9-13
SET LONGCHUNKSIZE ........................................................................................................... 9-13
SET PAGESIZE ........................................................................................................................... 9-13
ix
SET SERVEROUTPUT ............................................................................................................... 9-13
SET SQLPROMPT....................................................................................................................... 9-13
SET TAB ....................................................................................................................................... 9-14
SET TERMOUT ........................................................................................................................... 9-14
SET TRIMOUT ON
SET TRIMSPOOL ON ................................................................................................................ 9-14
UNDEFINE .................................................................................................................................. 9-14
10 SQL*Plus Security
PRODUCT_USER_PROFILE Table .............................................................................................. 10-1
Creating the PUP Table.............................................................................................................. 10-2
PUP Table Structure ................................................................................................................... 10-2
Description and Use of PUP Columns..................................................................................... 10-3
PUP Table Administration ........................................................................................................ 10-4
Disabling SQL*Plus, SQL, and PL/SQL Commands ................................................................. 10-4
Creating and Controlling Roles ..................................................................................................... 10-7
Disabling SET ROLE................................................................................................................... 10-7
Disabling User Roles .................................................................................................................. 10-8
Disabling Commands with SQLPLUS -RESTRICT................................................................... 10-9
Program Argument Security ......................................................................................................... 10-10
iSQL*Plus Security ......................................................................................................................... 10-10
Enabling SSL with iSQL*Plus.................................................................................................. 10-11
Administration Privileges ....................................................................................................... 10-11
Enabling DBA Access............................................................................................................... 10-11
Enabling or Disabling Restricted Database Access.............................................................. 10-12
Security Usage Notes ............................................................................................................... 10-12
x
12 SQL*Plus Globalization Support
Configuring Globalization Support in Command-line SQL*Plus ......................................... 12-2
SQL*Plus Client .......................................................................................................................... 12-2
Oracle Database .......................................................................................................................... 12-2
Configuring Multiple Language Support in iSQL*Plus........................................................... 12-2
Web Browser ............................................................................................................................... 12-2
Application Server...................................................................................................................... 12-3
NLS_LANG Environment Variable .............................................................................................. 12-3
Viewing NLS_LANG Settings .................................................................................................. 12-4
Setting NLS_LANG.......................................................................................................................... 12-5
xi
DISCONNECT ................................................................................................................................ 13-66
EDIT .................................................................................................................................................. 13-67
EXECUTE.......................................................................................................................................... 13-69
EXIT ................................................................................................................................................... 13-70
GET .................................................................................................................................................... 13-72
HELP.................................................................................................................................................. 13-74
HOST................................................................................................................................................. 13-75
INPUT ............................................................................................................................................... 13-77
LIST ................................................................................................................................................... 13-79
PASSWORD .................................................................................................................................... 13-81
PAUSE ............................................................................................................................................... 13-82
PRINT................................................................................................................................................ 13-83
PROMPT........................................................................................................................................... 13-84
RECOVER ....................................................................................................................................... 13-85
REMARK .......................................................................................................................................... 13-94
REPFOOTER .................................................................................................................................... 13-95
REPHEADER ................................................................................................................................... 13-97
RUN ................................................................................................................................................. 13-100
SAVE ............................................................................................................................................... 13-101
SET ................................................................................................................................................... 13-103
SET System Variable Summary ................................................................................................. 13-104
SET APPI[NFO]....................................................................................................................... 13-107
SET ARRAY[SIZE] .................................................................................................................. 13-109
SET AUTO[COMMIT] ........................................................................................................... 13-109
SET AUTOP[RINT]................................................................................................................. 13-109
SET AUTORECOVERY.......................................................................................................... 13-110
SET AUTOT[RACE] ............................................................................................................... 13-110
SET BLO[CKTERMINATOR] ............................................................................................... 13-111
SET CMDS[EP] ........................................................................................................................ 13-111
SET COLSEP ............................................................................................................................ 13-112
SET COM[PATIBILITY]......................................................................................................... 13-113
SET CON[CAT] ....................................................................................................................... 13-114
SET COPYC[OMMIT] ............................................................................................................ 13-114
SET COPYTYPECHECK ........................................................................................................ 13-114
SET DEF[INE].......................................................................................................................... 13-114
xii
SET DESCRIBE........................................................................................................................ 13-115
SET ECHO ............................................................................................................................... 13-116
SET EDITF[ILE]....................................................................................................................... 13-116
SET EMB[EDDED].................................................................................................................. 13-116
SET ESC[APE] ......................................................................................................................... 13-117
SET FEED[BACK] ................................................................................................................... 13-117
SET FLAGGER ........................................................................................................................ 13-118
SET FLU[SH] ........................................................................................................................... 13-118
SET HEA[DING]..................................................................................................................... 13-118
SET HEADS[EP] ..................................................................................................................... 13-119
SET INSTANCE ...................................................................................................................... 13-119
SET LIN[ESIZE] ...................................................................................................................... 13-120
SET LOBOF[FSET] .................................................................................................................. 13-120
SET LOGSOURCE .................................................................................................................. 13-121
SET LONG ............................................................................................................................... 13-121
SET LONGC[HUNKSIZE] .................................................................................................... 13-121
SET MARK[UP] ...................................................................................................................... 13-122
SET NEWP[AGE].................................................................................................................... 13-123
SET NULL................................................................................................................................ 13-124
SET NUMF[ORMAT] ............................................................................................................. 13-124
SET NUM[WIDTH] ................................................................................................................ 13-124
SET PAGES[IZE]..................................................................................................................... 13-124
SET PAU[SE] ........................................................................................................................... 13-125
SET RECSEP ............................................................................................................................ 13-125
SET RECSEPCHAR ................................................................................................................ 13-125
SET SERVEROUT[PUT]......................................................................................................... 13-126
SET SHIFT[INOUT]................................................................................................................ 13-128
SET SHOW[MODE] ............................................................................................................... 13-128
SET SQLBL[ANKLINES] ....................................................................................................... 13-129
SET SQLC[ASE] ...................................................................................................................... 13-129
SET SQLCO[NTINUE]........................................................................................................... 13-130
SET SQLN[UMBER] ............................................................................................................... 13-130
SET SQLPLUSCOMPAT[IBILITY] ....................................................................................... 13-130
SET SQLPRE[FIX] ................................................................................................................... 13-132
SET SQLP[ROMPT]................................................................................................................ 13-132
xiii
SET SQLT[ERMINATOR]...................................................................................................... 13-133
SET SUF[FIX] ........................................................................................................................... 13-133
SET TAB ................................................................................................................................... 13-134
SET TERM[OUT]..................................................................................................................... 13-134
SET TI[ME]............................................................................................................................... 13-134
SET TIMI[NG] ......................................................................................................................... 13-134
SET TRIM[OUT]...................................................................................................................... 13-135
SET TRIMS[POOL] ................................................................................................................. 13-135
SET UND[ERLINE] ................................................................................................................ 13-135
SET VER[IFY] .......................................................................................................................... 13-135
SET WRA[P] ............................................................................................................................ 13-135
SHOW ............................................................................................................................................. 13-136
SHUTDOWN ................................................................................................................................ 13-142
SPOOL ............................................................................................................................................ 13-144
START............................................................................................................................................. 13-146
STARTUP ...................................................................................................................................... 13-148
STORE............................................................................................................................................. 13-152
TIMING .......................................................................................................................................... 13-153
TTITLE ............................................................................................................................................ 13-155
UNDEFINE..................................................................................................................................... 13-159
VARIABLE ..................................................................................................................................... 13-160
WHENEVER OSERROR ............................................................................................................. 13-168
WHENEVER SQLERROR ........................................................................................................... 13-170
xiv
Part IV SQL*Plus Appendixes
A SQL*Plus Limits
Index
xv
xvi
Send Us Your Comments
SQL*Plus User’s Guide and Reference, Release 10.1
Part No. B12170-01
Oracle welcomes your comments and suggestions on the quality and usefulness of this publication.
Your input is an important part of the information used for revision.
Q Did you find any errors?
Q Is the information clearly presented?
Q Do you need more information? If so, where?
Q Are the examples correct? Do you need more examples?
Q What features did you like most about this manual?
If you find any errors or have any other suggestions for improvement, please indicate the title and
part number of the documentation and the chapter, section, and page number (if available). You can
send comments to us in the following ways:
Q Electronic mail: sqlplus@oracle.com
Q FAX: +61 3 9690 0043 Attn: Oracle SQL*Plus
Q Postal service:
Oracle Corporation Australia Pty Ltd
Oracle SQL*Plus Documentation
324 St Kilda Road
Melbourne, VIC 3004
Australia
If you would like a reply, please give your name, address, telephone number, and electronic mail
address (optional).
If you have problems with the software, please contact your local Oracle Support Services.
xvii
xviii
Preface
The SQL*Plus (pronounced "sequel plus") User's Guide and Reference introduces
the SQL*Plus program and its uses. It also provides a detailed description of each
SQL*Plus command.
Throughout this document, unless explicitly stated otherwise, SQL*Plus is used to
refer to SQL*Plus behavior available through all its user interfaces: command-line,
Windows Graphical User Interface and the iSQL*Plus web-based user interface.
This preface contains these topics:
Q Intended Audience
Q Documentation Accessibility
Q Structure
Q Related Documents
Q Conventions
xix
Intended Audience
The SQL*Plus User's Guide and Reference is intended for business and technical users
and system administrators who perform the following tasks:
Q Develop and run batch scripts
Q Format, calculate on, store, print and create web output from query results
Q Examine table and object definitions
Q Perform database administration
This document requires a basic understanding of the SQL language. If you do not
have familiarity with this database tool, see the Oracle Database SQL Reference. If you
plan to use the PL/SQL database language in conjunction with SQL*Plus, see the
PL/SQL User's Guide and Reference for information on using PL/SQL.
Documentation Accessibility
Our goal is to make Oracle products, services, and supporting documentation
accessible, with good usability, to the disabled community. To that end, our
documentation includes features that make information available to users of
assistive technology. This documentation is available in HTML format, and contains
markup to facilitate access by the disabled community. Standards will continue to
evolve over time, and Oracle is actively engaged with other market-leading
technology vendors to address technical obstacles so that our documentation can be
accessible to all of our customers. For additional information, visit the Oracle
Accessibility Program Web site at
http://www.oracle.com/accessibility/
xx
Structure
This document contains:
xxi
Chapter 6, "Using Scripts in SQL*Plus"
Contains further examples to help you learn to write and edit scripts containing
SQL*Plus, SQL and PL/SQL statements and commands.
xxii
PART IV, SQL*Plus Appendixes
Contains SQL*Plus Appendixes.
Related Documents
For more information, see these Oracle resources:
Q SQL*Plus Quick Reference
Q PL/SQL User's Guide and Reference
Q Oracle Database SQL Reference
Q Oracle Database Concepts
Q Oracle Database Administrator's Guide
Q Oracle Database Backup and Recovery Basics
Q Oracle Database Application Developer's Guide - Fundamentals
Q Oracle XML DB Developer's Guide
Q Oracle Database Globalization Support Guide
Q Oracle Database Heterogeneous Connectivity Administrator's Guide
Q Oracle Database Error Messages
Q Oracle Database Upgrade Guide
Q Oracle Database Reference
Q Oracle Database Performance Tuning Guide
xxiii
Q Oracle Net Services Administrator's Guide
Q Pro*COBOL Programmer's Guide
Q Pro*C/C++ Programmer's Guide
Q Oracle Database installation and user's manuals for your operating system
Many of the examples in this book use the sample schemas of the seed database,
which is installed by default when you install Oracle Database. Refer to Oracle
Database Sample Schemas for information on how these schemas were created and
how you can use them yourself.
SQL*Plus error message documentation is available in Chapter 14, "SQL*Plus Error
Messages". Oracle Database error message documentation is only available in
HTML. If you only have access to the Oracle Database Documentation CD, you can
browse the Oracle Database error messages by range. Once you find the specific
range, use your browser's "find in page" feature to locate the specific message.
When connected to the Internet, you can search for a specific error message using
the error message search feature of the Oracle Database online documentation.
Printed documentation is available for sale in the Oracle Store at
http://oraclestore.oracle.com/
If you already have a username and password for OTN, then you can go directly to
the documentation section of the OTN Web site at
http://otn.oracle.com/documentation/
Conventions
This section describes the conventions used in the text and code examples of this
documentation set. It describes:
Q Conventions in Text
Q Conventions in Code Examples
Q Conventions for Windows Operating Systems
xxiv
Conventions in Text
We use various conventions in text to help you more quickly identify special terms.
The following table describes those conventions and provides examples of their use.
xxv
Conventions in Code Examples
Code examples illustrate SQL, PL/SQL, SQL*Plus, or other command-line
statements. If users are expected to type them into the system, they are displayed in
a monospace (fixed-width) font and separated from normal text as follows:
SELECT username FROM dba_users WHERE username = 'MIGRATE';
PAGESIZE 24
The following table describes typographic conventions used in code examples and
provides examples of their use.
xxvi
Convention Meaning Example
. Vertical ellipsis points indicate that we SQL> SELECT NAME FROM V$DATAFILE;
. have omitted several lines of code not NAME
. directly related to the example. ------------------------------------
/fsl/dbs/tbs_01.dbf
/fs1/dbs/tbs_02.dbf
.
.
.
/fsl/dbs/tbs_09.dbf
9 rows selected.
Other notation You must enter symbols other than acctbal NUMBER(11,2);
brackets, braces, vertical bars, and ellipsis acct CONSTANT NUMBER(4) := 3;
points as shown.
Italics Italicized text indicates placeholders or CONNECT SYSTEM/system_password
variables for which you must supply DB_NAME = database_name
particular values.
UPPERCASE Uppercase typeface indicates elements SELECT last_name, employee_id
supplied by the system. We show these FROM employees;
terms in uppercase in order to distinguish SELECT * FROM USER_TABLES;
them from terms you define. Unless terms DROP TABLE hr.employees;
appear in brackets, enter them in the
order and with the spelling shown.
However, because these terms are not
case sensitive, you can enter them in
lowercase.
lowercase Lowercase typeface indicates SELECT last_name, employee_id
programmatic elements that you supply. FROM employees;
For example, lowercase indicates names sqlplus hr/your_password
of tables, columns, or files. CREATE USER mjones IDENTIFIED BY ty3MU9;
Note: Some programmatic elements use a
mixture of UPPERCASE and lowercase.
Enter these elements as shown.
xxvii
Conventions for Windows Operating Systems
The following table describes conventions for Windows operating systems and
provides examples of their use.
xxviii
Convention Meaning Example
ORACLE_HOME In releases prior to Oracle8i release 8.1.3, Go to the
and ORACLE_ when you installed Oracle Database ORACLE_BASE\ORACLE_HOME\rdbms\admin
BASE components, all subdirectories were directory.
located under a top level ORACLE_HOME
directory. For Windows NT, the default
location was C:\orant.
This release complies with Optimal
Flexible Architecture (OFA) guidelines.
All subdirectories are not under a top
level ORACLE_HOME directory. There is
a top level directory called ORACLE_BASE
that by default is C:\oracle. If you
install the latest Oracle Database release
on a computer with no other Oracle
software installed, then the default setting
for the first Oracle Database home
directory is C:\oracle\orann, where
nn is the latest release number. The
Oracle Database home directory is located
directly under ORACLE_BASE.
All directory path examples in this guide
follow OFA conventions.
Refer to Oracle Database Platform Guide
for Windows for additional information
about OFA compliances and for
information about installing Oracle
products in non-OFA compliant
directories.
xxix
xxx
What's New in SQL*Plus?
This section describes new features of SQL*Plus Release 10.1 and provides pointers
to additional information.
xxxi
Changes to SET SERVEROUTPUT ON
Changes to the way output from nested PL/SQL functions is displayed may change
the appearance of output with SET SERVEROUTPUT ON. SET SERVEROUTPUT
ON now correctly shows output (DBMS_OUTPUT.PUT_LINE) from a PL/SQL
function nested inside a SQL statement. Previously, output from a nested PL/SQL
function did not display until a subsequent PL/SQL function was executed.
SHOW RECYCLEBIN
A new option RECYCLEBIN original_name has been added to the SHOW command.
It enables users to view tables that are available for purging or reverting using the
new PURGE and FLASHBACK BEFORE DROP commands.
xxxii
You can view the predefined variable definitions in the same way as you view other
DEFINE definitions, using the DEFINE command with no arguments, or with the
specific argument you wish to display, for example:
DEFINE
or
DEFINE _PRIVILEGE
See Also:
Q Appendix B, "SQL*Plus COPY Command".
Q Chapter 14, "SQL*Plus Error Messages".
xxxiii
PAGESIZE Default
The default value of PAGESIZE has been changed from 24 to 14.
It is not to be confused with the SET COMPATIBILITY command which sets the
SQL language version.
xxxiv
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.
Q Resources
Q What is SQL*Plus
Q Before Starting SQL*Plus or iSQL*Plus
Q Starting SQL*Plus Command-line
Q Starting SQL*Plus Windows GUI
Q Starting and Stopping the iSQL*Plus Application Server
Q Starting iSQL*Plus
Q Connecting to a Different Database
Q Sample Schemas and SQL*Plus
Q Running your first Query
Q Exiting SQL*Plus
xxxv
Resources
Q SQL*Plus on the Oracle Technology Network at
http://otn.oracle.com/tech/sql_plus/.
Q SQL*Plus Discussion Forum at http://www.oracle.com/forums/.
Q Oracle Documentation Library at http://otn.oracle.com/documentation.
Q SQL*Plus Product and Documentation feedback by emailing
sqlplus@oracle.com.
What is SQL*Plus
SQL*Plus is an interactive and batch query tool that is installed with every Oracle
Database Server or Client installation. It has a command-line user interface, a
Windows Graphical User Interface (GUI) and the iSQL*Plus web-based user
interface.
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:
Q Format, perform calculations on, store, and print from query results
Q Examine table and object definitions
Q Develop and run batch scripts
Q Perform database administration
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, or using the dynamic reporting capability of iSQL*Plus
to run a script from a web page.
xxxvi
Before Starting SQL*Plus or iSQL*Plus
What is necessary before you can run SQL*Plus or iSQL*Plus?
Q Install Oracle Database (or Oracle Client for the command-line SQL*Plus or
Windows GUI interfaces only). See the Oracle Database Installation Guide for
your operating system available at http://otn.oracle.com/documentation/.
Q Obtain an Oracle Database login username and password during installation or
from your Database Administrator. See Login Username and Password.
Q Ensure a sample database is installed and that you have a login username and
password for it during Oracle Database installation. See Sample Schemas and
SQL*Plus.
Q 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 Connecting to a Database.
Q Ensure the database you want to connect to is started. See the STARTUP
command.
Q If using iSQL*Plus, ensure that you have the URL for the Application Server
you want to connect to, and that the Application Server is available and
running. See Starting the iSQL*Plus Application Server, and Testing if the
iSQL*Plus Application Server is Running.
2. When prompted, enter your Oracle Database username and password. If you
do not know your Oracle Database username and password, ask your Database
Administrator.
xxxvii
3. Alternatively, enter the SQL*Plus command in the form:
sqlplus username/password
3. The SQL*Plus Windows GUI opens and the Log On dialog is displayed.
Enter your Oracle Database username and password in the Log On dialog. If
you do not know your Oracle Database username and password, ask your
Database Administrator.
Leave the Host String field blank to connect to the default database. Enter a
connection identifier for the database you want to connect to in the Host String
field. You can connect to Oracle8i, Oracle9i and Oracle Database 10g databases.
xxxviii
4. Click OK. SQL*Plus starts and connects to the database.
Now you can start entering and executing SQL, PL/SQL and SQL*Plus
statements and commands at the SQL> prompt.
Starting iSQL*Plus
To start an iSQL*Plus session
1. Enter the iSQL*Plus URL in your web browser's Location or Address field. The
iSQL*Plus URL looks like:
http://machine_name.domain:port/isqlplus
If you do not know the iSQL*Plus URL, ask your System Administrator, or try
one of the following on the machine running the iSQL*Plus Application Server.
http://127.0.0.1:5560/isqlplus/
http://localhost:5560/isqlplus/
iSQL*Plus uses HTTP port 5560 by default. If iSQL*Plus is not available on port
5560, read the $ORACLE_HOME/install/portlist.ini file on the computer
running the iSQL*Plus Application Server to find the port on which iSQL*Plus
is running.
2. Press Enter to go to the URL. The iSQL*Plus Login screen is displayed in your
web browser.
3. Enter your Oracle Database username and password in the Username and
Password fields. If you do not know your Oracle Database username and
password, ask your Database Administrator.
4. Leave the Connection Identifier field blank to connect to the default database.
Enter an Oracle Database connection identifier in the Connection Identifier field
to connect to a database other than the default. You can connect to Oracle8i,
Oracle9i and Oracle Database 10g databases.
xxxix
If restricted database access has been configured, the Connection Identifier field
is a dropdown list of available databases to select.
5. Click Login to connect to the database. The iSQL*Plus Workspace is displayed
in your web browser.
Now you can start entering and executing SQL, PL/SQL and SQL*Plus
statements and commands in the Workspace.
xl
You need to unlock the HR account before you can use the HR sample schema. To
unlock the HR account, log in as the SYSTEM user and enter the following
command, where password is the password you want to define for the user HR:
ALTER USER HR IDENTIFIED BY password ACCOUNT UNLOCK;
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
FROM EMP_DETAILS_VIEW
WHERE LAST_NAME LIKE 'K%';
xli
which produces the following output:
Exiting SQL*Plus
It is recommended that you always use the Logout icon to exit iSQL*Plus to free up
system and server resources.
To exit SQL*Plus command-line, enter EXIT.
To exit the Windows GUI, enter EXIT or select Exit from the File menu.
In iSQL*Plus, the EXIT or QUIT command halts the script currently running, it does
not terminate your session.
xlii
Part I
SQL*Plus Getting Started
This section provides you with the information you need to get started with
SQL*Plus. It provides an overview of SQL*Plus, describes the command-line and
iSQL*Plus user interfaces, provides configuration information and information you
need to log in and run SQL*Plus.
The following chapters are covered in this section:
Q SQL*Plus Overview
Q SQL*Plus User Interface
Q Configuring SQL*Plus
Q Starting SQL*Plus
1
SQL*Plus Overview
This chapter introduces you to some general aspects of SQL*Plus. It has the
following topics:
Q What is SQL*Plus
Q SQL*Plus Command-line and Windows GUI Architecture
Q iSQL*Plus Architecture
Q SQL*Plus Installation
Q Who Can Use SQL*Plus
Q How Can I Learn SQL*Plus
Q How to Use the SQL*Plus Guide
Q Oracle Database Sample Schemas and SQL*Plus
What is SQL*Plus
SQL*Plus is an interactive and batch query tool that is installed with every Oracle
Database Server or Client installation. It has a command-line user interface, a
Windows Graphical User Interface (GUI) and the iSQL*Plus web-based user
interface.
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:
Q Format, perform calculations on, store, and print from query results
Q Examine table and object definitions
Q Develop and run batch scripts
SQL*Plus Client
The command-line user interface is the character based terminal implementation.
The Windows GUI is an alternate user interface available in Windows installations.
Oracle Database
Oracle Database Net components provide communication between the SQL*Plus
Client and Oracle Database.
iSQL*Plus Architecture
iSQL*Plus is a browser-based interface which uses the SQL*Plus processing engine
in a three-tier model comprising:
Q Client (Web browser).
Q Middle tier (Application Server).
Q Database (Oracle Database).
The iSQL*Plus Server is installed on the same machine as the Application Server.
The client may or may not also be on this machine. The middle tier coordinates
interactions and resources between the client tier and the database tier. The
database is Oracle8i, Oracle9i or Oracle Database 10g accessed through Oracle Net.
Web Browser
The iSQL*Plus user interface comprises web pages served to your web browser
through the Internet or your intranet. There is no installation or configuration
required for the iSQL*Plus user interface. You only need to know the URL of the
Application Server to access an available Oracle database.
Application Server
The Application Server is installed when Oracle Database is installed.
The middle tier contains a Java2 Enterprise Edition (J2EE) compliant application
server. It uses Oracle Containers for Java (OC4J) as the server engine. The
Application Server enables communication and authentication between the
iSQL*Plus user interface and Oracle Database.
Oracle Database
Oracle Net components provide communication between the iSQL*Plus
Application Server and Oracle Database in the same way as for a client server
installation of Oracle Database.
SQL*Plus Installation
SQL*Plus is a component of Oracle Database. SQL*Plus, and its command-line user
interface, Windows GUI, and iSQL*Plus web-based user interface are 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.
Keep a copy of your Oracle Database Installation Guide available for reference.
Similarly, to list column definitions for the EMPLOYEES table, enter the command:
DESCRIBE EMPLOYEES
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 wish to have
your own copies of the sample tables to use as you try the examples in this guide.
To get 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 remove the sample tables, perform the same steps but substitute HR_DROP.SQL
for HR_MAIN.SQL.
This chapter describes the SQL*Plus command-line user interface, the Windows
Graphical User Interface (GUI), and the iSQL*Plus web-based user interface. It
contains the following topics:
Q SQL*Plus Command-line User Interface
Q Windows Graphical User Interface
Q iSQL*Plus User Interface
Q Preferences and Equivalent SET Commands
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>
When the Windows GUI starts, it displays the same information as the
command-line user interface, and has the same default prompt:
SQL>
Key Function
Home Top of screen buffer
End Bottom of screen buffer
Page Up Previous screen page
Page Down Next screen page
Ctrl+Page Up Show page on left of current screen page
Ctrl+Page Down Show page on right of current screen page
Alt+F3 Find
F3 Find next
Ctrl+C Cancels the data fetch operation following command execution.
Ctrl+C Copies text - when no operations are running.
Ctrl+V Paste text
Shift+Del Clear the screen and the screen buffer
File Menu
The File menu has the following options:
Edit Menu
The Edit menu has the following options:
Search Menu
The Search menu has the following options:
Options Menu
The Options menu has the following options:
Help Menu
The Help menu has the following option:
You can choose any fixed-pitch TrueType font available in your Windows system
such as Courier New or Lucida Console. If you choose a proportional pitch font
such as Arial or Times New Roman, or if you enter an unavailable font, the registry
entry is ignored and the default font and size, Fixedsys 16, are used. If you choose
an unavailable font size, the default font size, 16, is used.
If you do not create the SQLPLUS_FONT registry entry, or if you do not specify a
value for SQLPLUS_FONT, the default font and size, Fixedsys 16, are used.
If you want to use particular characters, such as the Euro sign, you should make
sure that the fixed pitch font you choose contains those characters.
Note: If you have more than one Oracle Database installation, you
must select the HOME entry associated with the Windows GUI you
want to change. HOME0 is the registry entry for an Oracle
Database installation. A subsequent Oracle Database installation
will have the registry entry HOME1 and the next HOME2 and so
on.
Changes only affect a SQL*Plus Windows GUI started from the
associated Oracle Database installation, so you can use different
settings for each Oracle Database installation.
4. Click New String Value in the Edit menu. A new string value, with the default
name, NewValue #1 is created at the bottom of the right pane of the Registry
Editor. The default name of the new string value is selected ready for you to
replace with the name you want.
5. Enter SQLPLUS_FONT as the name of the new font face string value. If you
miskey the name or inadvertently enter it in mixed or lower case, you can edit
the name by selecting Rename from the Edit menu.
or
Enter SQLPLUS_FONT_SIZE as the name of the new font size string value. If
you miskey the name or inadvertently enter it in mixed or lower case, you can
edit the name by selecting Rename from the Edit menu.
6. Click Modify from the Edit menu or press Enter again to display the Edit String
dialog.
7. Enter the font name you want to use, such as Courier New, in the Value Data:
field. SQL*Plus will use the new font the next time you start the SQL*Plus
Windows GUI. The font must be a True Type fixed pitch font such as Courier
New or Lucida Console.
or
Enter the font size you want to use in pixels, such as 14, in the Value Data: field.
SQL*Plus will use the new font size the next time you start the SQL*Plus
Windows GUI. The size must be a size that exists on the client machine for the
specified font.
Note: You should not change the font face, font size or font subset
while any SQL*Plus Windows GUI is active. You should exit all
SQL*Plus Windows GUI sessions, make font face, font size and font
subset changes in the registry, exit the Registry Editor and then
restart the SQL*Plus Windows GUI to see the changes.
iSQL*Plus Navigation
There are a number of ways to navigate in iSQL*Plus:
Icons
Global navigation icons are displayed on each screen. Icons have two states:
Q A white background when that functionality is available
Q A blue background when active (when you have navigated to that screen)
Three navigation icons are always available after you have logged into iSQL*Plus:
Logout
Deletes your history list, ends your iSQL*Plus session, and displays the Login
screen with a message confirming that you have logged out.
Preferences
Opens the Preferences screen where you can configure interface settings, system
settings or change your password.
Help
Opens the iSQL*Plus Help in a separate web browser window. Help is also
available from the Login screen.
Tabs
Tabs appear on the top right of the current screen. Click a tab to go to that screen.
Menus
There are side menus to provide navigation to the screens comprising sections such
as Preferences. Click the link to go to the screen you want.
Footer Links
Footer links are navigation links to available screens shown at the bottom of each
page. Click a link to go to that screen.
Username:
Enter a valid username to connect to the Oracle Database (mandatory).
Password:
Enter a valid password for the username (mandatory).
Connection Identifier:
Leave this field blank to use the default Oracle database, otherwise enter a
connection identifier for the database you want to connect to.
[//]host[:port][/[service_name]]
Login
Click the Login button to log in to iSQL*Plus. If you enter an invalid username or
password, the Login screen is re-displayed with an error message.
The following dialog is displayed prompting you to enter your Application Server
authentication username and password.
User Name
Enter a valid Application Server authentication username. This may not be the
same as your Oracle Database username.
Password
Enter a valid Application Server authentication password for the username. This
may not be the same as your Oracle Database password.
After you have successfully authenticated, the iSQL*Plus DBA Login screen is
displayed:
Username:
Enter a valid username or / to connect to Oracle Database (mandatory).
Password:
Enter a valid password for the username.
Connection Identifier:
Leave this field blank to use the default Oracle database, otherwise enter a
connection identifier for the database you want to connect to.
[//]host[:port][/[service_name]]
Privilege:
The Privilege dropdown list has two options:
Q SYSDBA—connects to the specified database with SYSDBA privileges.
Q SYSOPER—connects to the specified database with SYSOPER privileges.
Login
Click the Login button to log in to iSQL*Plus with the supplied username,
password, connection identifier and DBA privilege. If you enter an invalid
username or password, you are returned to the Login screen and a message is
displayed.
iSQL*Plus Workspace
The Workspace consists of the Workspace, History and Load Script screens. After
successfully logging in, the Workspace is displayed. From the Workspace you can:
Q Enter, Execute and Cancel scripts
Q Load and Save scripts
Q View, Save and Print output
Q Access Preferences screens
Q Get help and Log out
The Workspace and History screens display the user's connection information in the
top right. The connection information is displayed in the form:
Connected as [username]@[connection_identifier] [AS SYSDBA| AS SYSOPER]
or
Not connected
Clear
Clears all statements in the Input area, and all displayed output. Cancels any script
that may be running.
It does not clear the SQL buffer, nor does it clear any variable values altered by
changing preferences or changing options of the SET command.
Execute
Executes the contents of the Input area. Depending on your preference settings, the
results are displayed in the Output area, in a new web browser window, or saved to
a file.
Load Script
Displays the Load Script screen where you enter a path and file name, or a URL for
the script you want to load into the Input area for editing or execution.
Save Script
Displays the File > Save As dialog where you enter a file name for the script you
want to save from the Input area as a plain text file. It may be useful to identify
scripts with an extension of .SQL.
Cancel
Cancels any script that is currently running, but does not clear the Input or Output
areas. A message saying that the script was cancelled is displayed.
Next Page
Displays the next page of report output. The Next Page button is displayed when
there are more results to display than can fit on the current output page or the script
contains a PAUSE command.
You can configure whether pages are displayed on a single page or multiple pages
using Preferences > Interface Configuration > Output Page Setup, or by executing
the SET PAUSE ON or SET PAUSE OFF command.
Fill out the fields on the DBA Workspace as you would for the iSQL*Plus
Workspace.
Script
Shows the current list of scripts in the history. They are in most recently executed
order, with the most recent at the top. Click the checkbox of one or more scripts that
you want to load into the Input area.
Scripts are displayed verbatim, so be careful if you have included items like
CONNECT commands which include passwords.
Load
Loads the selected scripts into the Input area of the Workspace.
Delete
Deletes the selected scripts from the history.
Click the Workspace tab to return to the Input area without loading or deleting any
scripts from the history.
iSQL*Plus displays:
Continue
Click the Continue button to execute the script in the Input area with the input
values you entered.
Cancel
Click the Cancel button to cancel execution of the script and return to the
Workspace.
Cancel
Click the Cancel button to cancel changes you have made on this Preferences
screen.
Apply
Click the Apply button to apply the changes you have made on this Preferences
screen.
Interface Configuration
Click Interface Configuration in the side menu to open the Interface Configuration
screen.
System Configuration
You can click one of the three entries under System Configuration in the side menu
to open these further three screens:
Q Script Formatting
Q Script Execution
Q Database Administration
Script Formatting
Click Script Formatting in the side menu to open the Script Formatting screen. You
use the Script Formatting screen to set options that affect the way script output is
displayed.
Each of these options contains either a field, set of radio buttons, or text area to
change the setting, with explanatory text.
Script Execution
Click Script Execution in the side menu to open the Script Execution screen. You use
the Script Execution screen to set options which affect the way scripts are executed.
Each of these options contains either a field, set of radio buttons, or text area to
change the setting, with explanatory text.
Database Administration
Click Database Administration in the side menu to open the Database
Administration screen. You use the Database Administration screen to set options
that affect database administration.
Each of these options contains either a field, set of radio buttons, or text area to
change the setting, with explanatory text.
Change Password
Click Change Password in the side menu to access the Change Password screen. See
"Changing Your Password in iSQL*Plus" on page 4-2.
The following tables show the profile scripts, and some commands and settings that
affect the Command-line, Windows and iSQL*Plus user interfaces.
Table 3–3 Commands in Profile scripts affecting SQL*Plus User Interface Settings
In a profile script, this affects the Command-line affects the iSQL*Plus
command ... and Windows GUI by ... Server by ...
SET Setting the SQL*Plus Setting the SQL*Plus
SQLPLUSCOMPAT[IBILITY] compatibility mode to compatibility mode to
{x.y[.z]} obtain the behavior the obtain the behavior the DBA
DBA wants for this site. wants for this site.
Also see the "SQL*Plus
Compatibility Matrix".
SQLPLUS command As for SET Not Applicable
COMPATIBILITY Option SQLPLUSCOMPATIBILITY
but set with the SQLPLUS
command
COMPATIBILITY option.
SQLPLUS command RESTRICT Starting SQL*Plus with the Not Applicable
Option RESTRICT option set to 3
prevents the User Profile
script from being read.
Site Profile
A Site Profile script is created during installation. It is used by the database
administrator to configure session wide behavior for SQL*Plus Command-line,
Windows GUI and iSQL*Plus connections.
The Site Profile script is generally named glogin.sql. SQL*Plus or the iSQL*Plus
Server executes this script whenever a user starts a SQL*Plus or iSQL*Plus session
and successfully establishes the Oracle Database connection.
The Site Profile enables the DBA to set up SQL*Plus environment defaults for all
users of a particular SQL*Plus or iSQL*Plus Application Server installation
Users cannot directly access the Site Profile.
User Profile
For SQL*Plus command-line and Windows GUI connections, SQL*Plus also
supports a User Profile script. The User Profile is executed after the Site Profile and
is intended to allow users to specifically customize their session. The User Profile
script is generally named login.sql. SQL*Plus searches for the User Profile in your
current directory, and then the directories you specify with the SQLPATH
environment variable. SQL*Plus searches this colon-separated list of directories in
the order they are listed.
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.
A user profile is not used in iSQL*Plus.
See Also:
Q SET command on page 13-103 for more information on these
and other SET command variables you may wish to set in your
SQL*Plus LOGIN file.
Q "Using Predefined Variables" on page 6-16 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 SUFFIX command to change the default file
extension.
If the file has the default extension (as specified by the SET SUFFIX 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.
PAGESIZE 24
SET PAGESIZE 60
SHOW PAGESIZE
PAGESIZE 60
The original values of system variables can then be restored from the script:
START plusenv
SHOW PAGESIZE
PAGESIZE 24
Running the helpins Shell Script or Batch File to Install Command-line Help
Run the provided shell script or batch file to install command-line help. In UNIX,
use the shell script, HELPINS, available in
$ORACLE_HOME/BIN
where password is the password you have defined for the SYSTEM user.
In Windows, run the batch file, HELPINS.BAT, from the command-line with:
%ORACLE_HOME%\BIN\HELPINS
In either case, the HELPINS utility reads the login from SYSTEM_PASS to
connect to Oracle Database using SQL*Plus, creates and loads the help tables,
and then disconnects. You can use command-line help the next time you start
SQL*Plus.
where your_password is 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
where your_password is 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.
3. The value specified by the attribute, port, is the port number that the
Application Server is attempting to use.
To view currently used ports and determine if the Application Server is trying to
use a port that is already in use, run the following command:
netstat -an
If there is another application using the same port, you need to change the port
used by the Application Server to a number that is not in use. By convention, it is
recommended that you use a port number above 2000, and that you do not use 80
or 8080 as they are usually used by web services. A port number can be any unique
integer number.
The number specified by the attribute, port, is the port number that the
Application Server is attempting to use.
4. Change the port number to a unique port number that you want the iSQL*Plus
Application Server to use.
5. Save http-web-site.xml.
2. Enter the following command to find the iSQL*Plus Application Server process:
$ ps -eaf|grep Djava
Logging can be set to ALL errors and messages, DEBUG messages, INFO messages,
WARNing messages, ERROR messages, FATAL errors, or to OFF. The settings are
changed by commenting or uncommenting the required lines in the
log4j.properties file. The following example shows the default setting, which
is to log FATAL errors:
# Set root logger level and its only appender to A1.
#log4j.rootLogger=ALL, A1
#log4j.rootLogger=DEBUG, A1
#log4j.rootLogger=INFO, A1
#log4j.rootLogger=WARN, A1
#log4j.rootLogger=ERROR, A1
log4j.rootLogger=FATAL, A1
#log4j.rootLogger=OFF, A1
Where the value is the number of whole minutes of idle time before the session
times out. It has a default value of 15 minutes. It can be set to any value from 1 to
1440 minutes. It should not be set so small that users do not get a chance to enter
their scripts.
When a user tries to use a timed out iSQL*Plus session, the Login screen is
displayed and the user is prompted to log in again. The following error is
displayed:
SP2-0864: Session has expired. Please log in again.
Entries in the param-value element should be identical to the alias for SERVICE_
NAMEs or SIDs set in your $ORACLE_HOME/network/admin/tnsnames.ora file.
Create Users
You can create multiple users who have access to the iSQL*Plus DBA URL. To
create a user from the JAZN shell, enter:
JAZN> adduser "iSQL*Plus DBA" username password
username and password are the username and password used to log into the
iSQL*Plus DBA URL.
To create multiple users, repeat the above command for each user.
List Users
You can confirm that users have been created and added to the iSQL*Plus DBA
realm. To confirm the creation of a user using the JAZN shell, enter:
JAZN> listusers "iSQL*Plus DBA"
To grant a user access to the webDba role from the command-line, enter:
$JAVA_HOME/bin/java -Djava.security.properties=$ORACLE_
HOME/sqlplus/admin/iplus/provider -jar $ORACLE_HOME/oc4j/j2ee/home/jazn.jar
-user "iSQL*Plus DBA/admin" -password admin_password -grantrole webDba
"iSQL*Plus DBA" username
Remove Users
To remove a user using the JAZN shell, enter:
JAZN> remuser "iSQL*Plus DBA" username
A dialog is displayed requesting authentication for the iSQL*Plus DBA URL. Log in
as the user you created above. You may need to restart iSQL*Plus for the changes to
take effect.
This example uses RSA as the key algorithm, keystore as the storage file name to
store the keys, sets the password to access the storage file as 123456, and is valid for
100 days. The keytool utility then prompts you for further information:
What is your first and last name?
[Unknown]: Test User
What is the name of your organizational unit?
[Unknown]: IT Department
What is the name of your organization?
[Unknown]: Oracle Corporation
What is the name of your City or Locality?
[Unknown]: San Francisco
What is the name of your State or Province?
[Unknown]: California
What is the two-letter country code for this unit?
[Unknown]: US
=[no]: yes
Owner: CN=Thawte Test CA Root, OU=TEST TEST TEST, O=Thawte Certification, ST=FO
TESTING PURPOSES ONLY, C=ZA
Issuer: CN=Thawte Test CA Root, OU=TEST TEST TEST, O=Thawte Certification, ST=F
R TESTING PURPOSES ONLY, C=ZA
Serial number: 0
Valid from: Thu Aug 01 10:00:00 EST 1996 until: Fri Jan 01 08:59:59 EST 2021
Certificate fingerprints:
MD5: 5E:E0:0E:1D:17:B7:CA:A5:7D:36:D6:02:DF:4D:26:A4
SHA1: 39:C6:9D:27:AF:DC:EB:47:D6:33:36:6A:B2:05:F1:47:A9:B4:DA:EA
In this example, an alias, servertest, is created for the root certificate, servertest.cer.
In this example, the certificate request file is named mycsr.csr. Use the contents of
mycsr.csr to request a new certificate from your CA. Create a new file called
mycert.cer and paste in the contents of your new certificate.
2. Edit secure-web-site.xml and set the port number, and add the attribute
secure="true":
<web-site port="4443" secure="true" display-name="Oracle9iAS Containers for
J2EE HTTP Web Site">
The port you use for iSQL*Plus in SSL mode can be any free port on your
machine. In this example, it is set to port 4443. The default SSL port is 443.
3. Add a new element to the web-site element in the secure-web-site.xml file.
<ssl-config keystore="/oracle/ora10g/oc4j/j2ee/keystore"
keystore-password="123456" />
For detailed information about implementing SSL, see the Oracle Application Server
Containers for J2EE Security Guide.
The Oracle Net connection between the iSQL*Plus Server and Oracle Database
provides the same security as in previous client server architectures. For more
information about Oracle Net connection security, see the Oracle Net Services
Administrator's Guide and the Oracle Advanced Security Administrator’s Guide.
or to enable or disable iSQL*Plus Help, the application tag has the form,
<application name="isqlplushelp" ...>. The syntax of the line to change in the
configuration file to disable or enable iSQL*Plus Help is:
<application name="isqlplushelp" path="../applications/isqlplushelp.ear"
auto-start="true" />
Where the parameter is set OFF, or if it does not exist or has an invalid value, users
cannot use SET MARKUP HTML HEAD text BODY text TABLE text ENTMAP or
COLUMN ENTMAP to create user defined HTML. If Map Special Characters to
HTML Entities is set OFF in the Script Formatting Preferences screen, the value is
ignored and reverts to ON. The default value for iSQLPlusAllowUserMarkup is
OFF. Leaving it set OFF provides greater security.
Where the parameter is set ON, users can execute SET MARKUP HTML HEAD text
BODY text TABLE text ENTMAP and COLUMN ENTMAP commands to change
the status of entity mapping for the iSQL*Plus session or report column. This
enables custom HTML to be included in iSQL*Plus report output.
Session Integrity
Each iSQL*Plus login is uniquely identified, so you can:
Q Connect multiple times from the same machine
Q Connect multiple times from different machines
iSQL*Plus supports this stateful behavior by storing session context information in
the Application Server. You must ensure that your Application Server always
routes HTTP requests to the same server, otherwise the session context will not be
found. However, you may find it useful to start more than one Application Server
to distribute user load across the multiple servers.
Example 3–2
The ARRAYSIZE is set to 15, the default value.
Example 3–3
To change the ARRAYSIZE, click Custom and enter the number in the text box.
Example 3–4
The default for ECHO is off. To change the setting, click Custom and then click On.
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:
Q Login Username and Password
Q Connecting to a Database
Q Starting SQL*Plus
Q Exiting SQL*Plus
Q SQLPLUS Program Syntax
For further information about the default logins, see the Oracle Database
Administrator's Guide.
Once you have logged in, you can connect under a different username with the
SQL*Plus CONNECT command. The username and password must be valid for the
database. For example, to connect the username TODD to the default database
using the password FOX, you could enter
CONNECT TODD/FOX
In the command-line interface, if you omit the username and password, SQL*Plus
prompts you for them. You also have the option of typing only the username
following CONNECT and omitting the password (SQL*Plus then prompts for the
password). Because CONNECT first disconnects you from your current database,
you will be left unconnected to any database if you use an invalid username and
password in your CONNECT command.
If you log on or connect as a user whose account has expired, you are prompted to
change your password before you can connect.
If an account is locked, a message is displayed and connection as this user is not
permitted until the account is unlocked by your DBA.
You can use the DISCONNECT command to disconnect from a database without
leaving SQL*Plus.
Username:
Enter your Oracle Database account username.
Old password:
Enter your current Oracle Database account password.
New password:
Enter your new password.
Apply
Click the Apply button to change the password for your Oracle Database account.
Cancel
Click the Cancel button to clear the screen without changing your password.
Expired Password
In the command-line interface, if your password has expired, SQL*Plus prompts
you to change it when you attempt to log in. You are logged in once you
successfully change your password.
Connecting to a Database
You must connect to an Oracle Database (instance) before you can query or modify
data in that database. You can connect to the default database and to other
databases accessible through your network. To connect to another database over a
network, both databases must have Oracle Net configured, and have compatible
network drivers. 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:
To use a net service name (alias), it must have an entry in the tnsnames.ora file on
the machine running SQL*Plus, or for iSQL*Plus, the machine running the
iSQL*Plus Application Server. An entry in tnsnames.ora is not required if you use a
connection identifier.
Example 4–2 Start a command-line session to the sales database using the net
service name
SQLPLUS hr/password@SALES1
See the Oracle Net Services Reference Guide and the Oracle Net Services Administrator's
Guide for more information about database connections and net service name
definitions.
Example 4–4 Start a command-line session to the sales database using the easy
connection identifier
sqlplus hr/password@sales-server:1521/sales.us.acme.com
Example 4–5 CONNECT to the sales database using the easy connection identifier
connect hr/password@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.
Starting SQL*Plus
If you are connecting to a remote Oracle database, make sure your Oracle Net
software is installed and working properly. For more information, see the Oracle Net
Services Administrator's Guide.
When you start a SQL*Plus command-line or Windows GUI session, and after a
CONNECT command in that session, the site profile, glogin.sql, and the user profile
file, login.sql, are processed:
Q After SQL*Plus starts and connects, and prior to displaying the first prompt.
Q After SQL*Plus starts and connects, and prior to running a script specified on
the command-line.
Q Prior to the first prompt when /NOLOG is specified on the command-line and
no connection is made.
The site profile file, glogin.sql is processed first, then the user profile file, login.sql.
When you start an iSQL*Plus session, and after a CONNECT command in that
session, the site profile, glogin.sql, is processed:
Q After iSQL*Plus starts and connects.
Q After iSQL*Plus starts and connects, and prior to running a script specified in a
dynamic URL.
Behavior in SQL*Plus 10.1 may be unexpected depending on the setting of SET
SQLPLUSCOMPATIBILITY. For example, processing glogin.sql and login.sql after
a CONNECT command only occurs with the default SQLPLUSCOMPATIBILITY
setting of 10.1. For more information, see SET SQLPLUSCOMPAT[IBILITY] {x.y[.z]}
on page 13-130.
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):
4. Enter your username and press Return. SQL*Plus displays the prompt "Enter
password:".
5. Enter your password and press Return again. For your protection, your
password does not appear on the screen.
The process of entering your username and password is called logging in.
SQL*Plus displays the version of Oracle Database to which you connected and
the versions of available tools such as PL/SQL.
Next, SQL*Plus displays the SQL*Plus command prompt:
SQL>
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.
Enter a valid user name and password. If you are connecting to a remote Oracle
database, enter the Oracle Net connect identifier in the Host String field. To
connect to the default database, leave the Host String field blank. See Easy
Connection Identifier earlier for more information about configuring and using
Oracle Net connect identifiers.
2. Click OK.
The SQL*Plus graphical user interface starts. You can optionally include your
login username and password separated by a slash (/), and a database to
connect to, for example:
C:\> SQLPLUSW username/password@connect_identifier
2. Enter
$ORACLE_HOME/bin/isqlplusctl start
2. Enter
%ORACLE_HOME%\bin\isqlplusctl start
iSQL*Plus uses HTTP port 5560 by default. If iSQL*Plus is not available on port
5560, read the $ORACLE_HOME/install/portlist.ini file to find the port on
which iSQL*Plus is running.
2. Enter one of the following URLs from a web browser on the machine running
the iSQL*Plus Application Server if you do not know the iSQL*Plus URL:
http://127.0.0.1:5560/isqlplus/
http://localhost:5560/isqlplus/
2. Enter
$ORACLE_HOME/bin/isqlplusctl stop
2. Enter
%ORACLE_HOME%\bin\isqlplusctl stop
Running iSQL*Plus
To start an iSQL*Plus session
1. Enter the Uniform Resource Locator (URL) of iSQL*Plus in the Location field of
your web browser, for example:
http://machine_name.domain:port/isqlplus
where machine_name.domain is the URL, and port is the port number for the
Application Server you want to use. The iSQL*Plus Login screen is displayed.
Each successful login is uniquely identified, so you can have multiple
iSQL*Plus sessions running from the same machine, or from multiple client
machines.
To access the iSQL*Plus DBA URL, you must set up login credentials using the
Oracle JAAS Provider, known as JAZN (Java AuthoriZatioN). See Enabling
iSQL*Plus DBA Access on page 3-17 for information on accessing the iSQL*Plus
DBA URL.
When you are connected through the iSQL*Plus DBA URL, the Application Server
authentication enables AS SYSDBA or AS SYSOPER connections through the DBA
Login screen, or through a CONNECT command, but the Oracle Database
username and password authentication may still prevent access.
where
machine_name.domain is the URL of the Application Server
port is the number of the port used by the Application Server
UserOpts is UserLogin|Script|UserLogin&Script
DBAOpts is DBALogin|Script|DBALogin&Script
and
UserLogin is userid=username[/password][@connect_identifier]
DBALogin is userid={username[/password][@connect_identifier]
| / } AS {SYSDBA | SYSOPER}
Script is script=text[&type={url|text}][&action={execute|load}][&variable=value ...]
If there is no userid URL parameter or if it has incomplete information, iSQL*Plus
displays the login screen. If the URL parameter is complete and the login
information is valid, iSQL*Plus connects and continues with the request.
SQL script parameters can be given in any order. If any user variable script
parameter begins with a reserved keyword, such as script or userid, iSQL*Plus may
interpret it as a command rather than as a literal parameter.
If the URL parameter type is url, or if it is not specified, the script parameter is
assumed to be the URL of a SQL script.
If the URL parameter type is text, the text in the script parameter is assumed to be
the contents of the SQL script itself. There may be HTML character set restrictions
on scripts passed using this method.
If the URL parameter action is execute, or if it is not specified, the SQL script is
executed in iSQL*Plus.
If the URL parameter action is load, the script is loaded into the Workspace, but it is
not executed. A web browser may not be able to display large scripts in the
Workspace, and as a result, scripts may be truncated.
Examples
To log into iSQL*Plus with the username HR and password your_password, enter
http://machine_name.domain:5560/isqlplus/dynamic?userid=HR/your_password
To execute a script that is located at a URL, pass the username and password, login
to a database, and pass parameters to the script to provide values for substitution
variables, enter
http://machine_name.domain:5560/isqlplus/dba/dynamic?userid=hr/your_
password@oracle10g%20as%20sysdba&script=ftp://machine_
name2.domain/script.sql&name=*&salary=12000
Exiting SQL*Plus
The way you exit SQL*Plus from each of the three user interfaces is described in the
following sections.
If you fail to log in to SQL*Plus successfully because your username or password is
invalid or some other error, SQL*Plus will return an error status equivalent to an
EXIT FAILURE command. See the EXIT command on page 13-70 for further
information.
Options
The following sections contain descriptions of SQLPLUS command options:
COMPATIBILITY Option
-C[OMPATIBILITY] {x.y[.z]
Sets the value of the SQLPLUSCOMPATIBILITY system variable to the SQL*Plus
release specified by x.y[.z]. Where x is the version number, y is the release number,
and z is the update number. For example, 9.0.1 or 10.1. For more information, see
the SET SQLPLUSCOMPAT[IBILITY] {x.y[.z]}system variable on page 13-130.
HELP Option
-H[ELP]
Displays the usage and syntax for the SQLPLUS command, and then returns control
to the operating system.
VERSION Option
-V[ERSION]
Displays the current version and level number for SQL*Plus, and then returns
control to the operating system.
LOGON Option
-L[OGON]
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 -LOGON option is not supported in the Windows GUI.
MARKUP Options
-M[ARKUP]
You can use the MARKUP option to generate a complete stand alone web page
from your query or script. MARKUP currently supports HTML 4.0 transitional.
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.
In SQL*Plus, use the SHOW MARKUP command to view the status of MARKUP
options.
The SQLPLUS -MARKUP command has the same options and 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.
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. The default
is OFF.
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
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 on page 13-31.
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.
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}
PREFORMAT ON or OFF specifies whether or not SQL*Plus writes output to the
<PRE> tag or to an HTML table. The default is OFF, so output is written to a HTML
table by default. You can turn PREFORMAT ON and OFF as required during a
session.
Notes: 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
RESTRICT Option
-R[ESTRICT] {1|2|3}
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.
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.
SILENT Option
-S[ILENT]
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.
Logon
username[/password]
Represent the username and password with which you wish to start SQL*Plus and
connect to Oracle Database. If you enter your password on the command-line as
part of the SQLPLUS command in the form,
sqlplus username[/password]
password prompts are not visible – your username will appear 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 communications protocol your Oracle Database installation uses. For
more information, refer to the Oracle Net manual appropriate for your protocol or
contact your DBA.
/
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 the Oracle Database
Administrator's Guide for information about operating system authentication.
AS {SYSOPER|SYSDBA}
The AS clause enables privileged connections by users who have been granted
SYSOPER or SYSDBA system privileges.
/NOLOG
Establishes no initial connection to Oracle Database. Before issuing any SQL
commands, you must issue a CONNECT command to establish a valid logon. Use
/NOLOG when you want to have a SQL*Plus script prompt for the username,
password, or database specification. The first line of this script is not assumed to
contain a logon.
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 on page 13-146 for more information.
This section 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.
The following chapters are covered in this section:
Q SQL*Plus Basics
Q Using Scripts in SQL*Plus
Q Formatting SQL*Plus Reports
Q Generating HTML Reports from SQL*Plus
Q Tuning SQL*Plus
Q SQL*Plus Security
Q Database Administration with SQL*Plus
Q SQL*Plus Globalization Support
5
SQL*Plus Basics
This chapter helps you learn the basics of using SQL*Plus. It has the following
topics:
Q Entering and Executing Commands
Q Listing a Table Definition
Q Listing PL/SQL Definitions
Q Running SQL Commands
Q Running PL/SQL Blocks
Q Running SQL*Plus Commands
Q System Variables that Affect How Commands Run
Q Stopping a Command while it is Running
Q Running Operating System Commands
Q Pausing the Display
Q Saving Changes to the Database Automatically
Q Interpreting Error Messages
Executing Commands
In command-line SQL*Plus, you type a command and direct SQL*Plus to execute it
by pressing the Return key. SQL*Plus processes the command and re-displays the
command prompt when ready for another command.
In iSQL*Plus, you type a command or a script into the Input area and click the
Execute button to execute the contents of the Input area. The results of your script
are displayed below the Input area by default. Use the History screen to access and
rerun commands previously executed in the current session.
iSQL*Plus executes the last SQL or PL/SQL statement even if it is incomplete or
does not have a final ";" or "/". If you intend to run iSQL*Plus scripts in the
command-line or Windows GUI, you should make sure you use a ";" or "/" to
terminate your final statement.
iSQL*Plus retains the state of your current system variables and other options
throughout your session. If you use the History screen to re-execute a script, you
may get different results from those previously obtained, depending on the current
system variable values.
Some SQL*Plus commands have no logical sense or are not applicable in iSQL*Plus.
See Appendix D, "Commands Not Supported in iSQL*Plus"
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 (not in iSQL*Plus).
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:
6 rows selected.
After displaying the results and the number of rows retrieved, SQL*Plus
command-line and Windows GUI display the command prompt again. If you
made a mistake and therefore did not get the results shown, re-enter the
command (or edit the command in the Input area in iSQL*Plus).
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" on
page 7-33. Typically, LINESIZE is set to 80 in command-line and Windows GUI,
and 150 in iSQL*Plus. 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" on page 5-12 for more
information.
In this guide, you will find most SQL commands divided into clauses, one clause on
each line. In Example 5–3, "Entering a SQL Command", 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.
Note: You can change the way empty lines in SQL statements
behave using the SET SQLBLANKLINES command (not in
iSQL*Plus). For more information about changing blank line
behavior, see the SET command on page 13-103.
To execute commands this way, press Return again; SQL*Plus now prompts you
with the SQL*Plus command prompt (not in iSQL*Plus). SQL*Plus does not execute
the command, but stores it in the SQL buffer. See "The SQL Buffer" on page 5-3 for
details. If you subsequently enter another SQL command, SQL*Plus overwrites the
previous command in the buffer.
.
/
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, or click Execute in iSQL*Plus to
run it:
SELECT EMPLOYEE_ID, LAST_NAME, JOB_ID, SALARY
FROM EMP_DETAILS_VIEW WHERE SALARY > 12000;
6 rows selected.
The COLUMN command formatted the column SALARY with a dollar sign ($) and
a comma (,) and gave it a new heading.
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.
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
Chapter 7, "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.
Alternatively, you can enter the following to turn the autocommit feature on:
SET AUTOCOMMIT IMMEDIATE
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.
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
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:
Q If the error is a numbered error beginning with the letters "SP2", look up the
SQL*Plus message in "SQL*Plus Error Messages" on page 14-1.
Q If the error is a numbered error beginning with the letters "CPY" look up the
SQL*Plus COPY command message in "COPY Command Messages" on
page 14-54.
Q 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.
Q If the error is a numbered error beginning with the letters "PLS", look up the
Oracle Database message in the PL/SQL User's Guide and Reference.
If the error is unnumbered, look up correct syntax for the command that generated
the error in Chapter 13, "SQL*Plus Command Reference" for a SQL*Plus command,
in the Oracle Database SQL Reference for a SQL command, or in the PL/SQL User's
Guide and Reference for a PL/SQL block. Otherwise, contact your DBA.
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:
Q Editing Scripts
Q Editing Scripts in SQL*Plus Command-Line
Q Placing Comments in Scripts
Q Running Scripts
Q Nesting Scripts
Q Exiting from a Script with a Return Code
Q Defining Substitution Variables
Q Using Predefined Variables
Q Using Substitution Variables
Q Substitution Variables in iSQL*Plus
Q Passing Parameters through the START Command
Q Communicating with the User
Q Using Bind Variables
Q Using REFCURSOR Bind Variables
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
Chapter 1, "SQL*Plus Overview".
Editing Scripts
In the command-line and Windows GUI, the use of an external editor in
combination with the @, @@ or START commands is an effective method of creating
and executing generic scripts. You can write scripts which contain SQL*Plus, SQL
and PL/SQL commands, which you can retrieve and edit. This is especially useful
for storing complex commands or frequently used reports.
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 and iSQL*Plus Configuration" on
page 3-4, and the DEFINE and EDIT commands in Chapter 13, "SQL*Plus
Command Reference" 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.
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 on page 13-31
and in the Oracle Database SQL Reference.
Now use your editor's save command to store your query in a file called
SALES.SQL.
These are useful if you want to correct or modify a command you have entered.
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.
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:
Q the word CHANGE or the letter C
Q the sequence of characters you want to change
Q 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.
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 5–4,
"Entering a SQL*Plus Command (not in iSQL*Plus)". (If you have left SQL*Plus and
started again since performing Example 5–4, "Entering a SQL*Plus Command (not
in iSQL*Plus)" the column has reverted to its original format.)
See CHANGE command on page 13-26 for information about the significance of
case in a CHANGE command and on using wildcards to specify blocks of text in a
CHANGE command.
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.
Deleting Lines
Use the DEL command to delete lines in the buffer. Enter DEL specifying the line
numbers you want to delete.
Suppose you want to delete the current line to the last line inclusive. Use the DEL
command as shown.
DEL * LAST
DEL makes the following line of the buffer (if any) the current line.
See DEL on page 13-57 for more information.
Using /*...*/
Enter the SQL comment delimiters, /*...*/, on separate lines in your script, on the
same line as a SQL command, or on a line in a PL/SQL block.
You must enter a space after the slash-asterisk(/*) beginning a comment.
The comments can span multiple lines, but cannot be nested within one another:
/* Commission Report
to be run monthly. */
COLUMN LAST_NAME HEADING 'LAST_NAME';
COLUMN SALARY HEADING 'MONTHLY SALARY' FORMAT $99,999;
COLUMN COMMISSION_PCT HEADING 'COMMISSION %' FORMAT 90.90;
REMARK Includes only salesmen;
SELECT LAST_NAME, SALARY, COMMISSION_PCT
FROM EMP_DETAILS_VIEW
/* Include only salesmen.*/
WHERE JOB_ID='SA_MAN';
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:
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
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.
-- COMMENT
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected
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 on page 13-103.
Running Scripts
The START command retrieves a script and runs the commands it contains. Use
START to run a script containing SQL commands, PL/SQL blocks, and SQL*Plus
commands. You can have many commands in the file. Follow the START command
with the name of the file:
START file_name
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:
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.
Q Include your username, a slash (/), and your password as the first line of the
file. Follow the SQLPLUS command with @ and the filename. SQL*Plus starts
and runs the file. Please consider the security risks of exposing your password
in the file before using this technique.
If you omit the slash (/) and password, SQL*Plus prompts for it.
Nesting Scripts
To run a series of scripts in sequence, first create a script containing several START
commands, each followed by the name of a script in the sequence. Then run the
script containing the START commands. For example, you could include the
following START commands in a script named SALESRPT:
START Q1SALES
START Q2SALES
START Q3SALES
START Q4SALES
START YRENDSLS
To confirm the variable definition, enter DEFINE followed by the variable name:
DEFINE L_NAME
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
later in this chapter.
To delete a substitution variable, use the SQL*Plus command UNDEFINE followed
by the variable name.
See Also:
"Predefined Variables" on page 13-53 for a list of the predefined
variables and examples of their use.
as if they were
SELECT JOB_ID, SALARY
FROM EMP_DETAILS_VIEW
WHERE SALARY>12000;
after substitution. You can suppress this listing by setting the SET command
variable VERIFY to OFF.
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.
is interpreted as
SELECT SALARY FROM EMP_DETAILS_VIEW WHERE EMPLOYEE_ID='205';
SELECT &GROUP_COL,
MAX(&NUMBER_COL) MAXIMUM
FROM &TABLE
GROUP BY &GROUP_COL
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:
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
Restrictions
You cannot use substitution variables in the buffer editing commands, APPEND,
CHANGE, DEL, and INPUT, nor in other commands where substitution would be
meaningless. The buffer editing commands, APPEND, CHANGE, and INPUT, treat
text beginning with "&" or "&&" literally, like any other text string.
See SET on page 13-103 for more information about system variables.
iSQL*Plus displays:
Continue
Click the Continue button to execute the script in the Input area with the input
values you entered.
Cancel
Click the Cancel button to cancel execution of the script and return to the
Workspace.
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.
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:
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
SAVE PROMPT1
The TTITLE command sets the top title for your report. See "Defining Page and
Report Titles and Dimensions" on page 7-24 for more information about the
TTITILE command.
Finally, run the script, responding to the prompt for the title as shown:
START PROMPT1
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
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:
Employee ID. :
one
In iSQL*Plus, PAUSE displays a Next Page button. Users must click Next Page to
continue.
This command creates a bind variable named ret_val with a datatype of NUMBER.
See the VARIABLE command on page 13-160 for more information. (To list all bind
variables created in a session, type VARIABLE without any arguments.)
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 on page 13-83 for
more information about displaying bind variables.
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 the
PL/SQL User's Guide and Reference for 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;
/
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 PROCEDURE EmpInfo_rpt
(emp_cv IN OUT cv_types.EmpInfoTyp) AS
BEGIN
OPEN emp_cv FOR SELECT EMPLOYEE_ID, SALARY
FROM EMP_DETAILS_VIEW
WHERE JOB_ID='SA_MAN' ;
END;
/
Procedure created.
EMPLOYEE_ID SALARY
----------- ----------
145 14000
146 13500
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
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:
Q Formatting Columns
Q Clarifying Your Report with Spacing and Summary Lines
Q Defining Page and Report Titles and Dimensions
Q 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
Chapter 1, "SQL*Plus Overview".
Formatting Columns
Through the SQL*Plus COLUMN command, you can change the column headings
and reformat the column data in your query results.
Default Headings
SQL*Plus uses column or expression names as default column headings when
displaying query results. Column names are often short and cryptic, however, and
expressions can be hard to understand.
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 on page 13-103 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
Default Display
A NUMBER column's width equals the width of the heading or the width of the
FORMAT plus one space for the sign, whichever is greater. If you do not explicitly
use FORMAT, then the column's width will always be at least the value of SET
NUMWIDTH.
SQL*Plus normally displays numbers with as many digits as are required for
accuracy, up to a standard display width determined by the value of the
NUMWIDTH variable of the SET command (normally 10). If a number is larger
than the value of SET NUMWIDTH, SQL*Plus rounds the number up or down to
the maximum number of characters allowed if possible, or displays hashes if the
number is too large.
You can choose a different format for any NUMBER column by using a format
model in a COLUMN command. A format model is a representation of the way you
want the numbers in the column to appear, using 9s to represent digits.
Use format models to add commas, dollar signs, angle brackets (around negative
values), and leading zeros to numbers in a given column. You can also round the
values to a given number of decimal places, display minus signs to the right of
negative values (instead of to the left), and display values in exponential notation.
To use more than one format model for a single column, combine the desired
models in one COLUMN command (see Example 7–4). See COLUMN on
page 13-31 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.
Formatting Datatypes
When displaying datatypes, you can either accept the SQL*Plus default display
width or you can change it using the COLUMN command. The format model will
stay in effect until you enter a new one, reset the column's format with
COLUMN column_name CLEAR
or exit from SQL*Plus. Datatypes, in this manual, include the following types:
Q CHAR
Q NCHAR
Q VARCHAR2 (VARCHAR)
Default Display
The default width of datatype columns is the width of the column in the database.
The column width of a LONG, CLOB, NCLOB or XMLType defaults to the value of
SET LONGCHUNKSIZE or SET LONG, whichever is the smaller.
The default width and format of unformatted DATE columns in SQL*Plus is
determined by the database NLS_DATE_FORMAT parameter. Otherwise, the
default format width is A9. See the FORMAT clause of the COLUMN command on
page 13-31 for more information on formatting DATE columns.
Left justification is the default for datatypes.
If you specify a width shorter than the column heading, SQL*Plus truncates the
heading. See the COLUMN command on page 13-31 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 7–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
TRUNCATED clauses of the COLUMN command. See the COLUMN command on
page 13-31 for more information on these clauses. You will use the WORD_
WRAPPED clause of COLUMN later in this chapter.
To set the XMLType column width to 20 characters and then select the XMLType
column, enter
COLUMN Building FORMAT A20
SELECT
w.warehouse_spec.extract('/Warehouse/Building/text()').getStringVal()
"Building"
FROM warehouses w;
Building
--------------------
Owned
For more information about the createXML, extract, text and getStringVal functions,
and about creating and manipulating XMLType data, see Oracle XML API Reference.
LAST MONTHLY
NAME SALARY BONUS
---------- -------- --------
Russell $14,000 $0
Partners $13,500 $0
Errazuriz $12,000 $0
Cambrault $11,000 $0
Zlotkey $10,500 $0
To list the current display attributes for 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
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
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.
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 rows selected.
To make this report more useful, you would use BREAK to establish
DEPARTMENT_ID as the break column. Through BREAK you could suppress
duplicate values in DEPARTMENT_ID and place blank lines or begin a new page
between departments. You could use BREAK in conjunction with COMPUTE to
calculate and print summary lines containing the total salary for each department
and for all departments. You could also print summary lines containing the
average, maximum, minimum, standard deviation, variance, or row count.
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 rows selected.
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.
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
Page: 1
DEPARTMENT_ID JOB_ID LAST_NAME SALARY
------------- ---------- ------------------------- ----------
20 MK_MAN Hartstein 13000
Page: 2
DEPARTMENT_ID JOB_ID LAST_NAME SALARY
------------- ---------- ------------------------- ----------
80 SA_MAN Russell 14000
Partners 13500
Page: 3
DEPARTMENT_ID JOB_ID LAST_NAME SALARY
------------- ---------- ------------------------- ----------
90 AD_PRES King 24000
6 rows selected.
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.
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 on
page 13-42 for more details. If you use the NOPRINT option for the column on
which the COMPUTE is being performed, the COMPUTE result is also suppressed.
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
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.
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
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
Example 7–15 Computing the Same Type of Summary Value on Different Columns
To print the total of salaries and commissions for all sales people, first enter the
following COMPUTE command:
COMPUTE SUM OF SALARY COMMISSION_PCT ON REPORT
You do not have to enter a BREAK command; the BREAK you entered in
Example 7–14 is still in effect. Now, change the first line of the select query to
include COMMISSION_PCT:
1
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.
Example 7–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
6 rows selected.
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.
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 ...
For descriptions of all TTITLE, BTITLE, REPHEADER and REPFOOTER clauses, see
the TTITLE and REPHEADER commands in Chapter 13, "SQL*Plus Command
Reference".
COMPANY CONFIDENTIAL
6 rows selected.
which displays the following two pages of output, with the new REPHEADER
displayed on the first page:
COMPANY CONFIDENTIAL
COMPANY CONFIDENTIAL
6 rows selected.
A C M E W I D G E T
====================
PERSONNEL REPORT SALES DEPARTMENT
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'
ACME WIDGET
SALES DEPARTMENT PERSONNEL REPORT
COMPANY CONFIDENTIAL
6 rows selected.
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 on
page 13-155 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).
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
You must include the master column in an ORDER BY clause and in a BREAK
command using the SKIP PAGE clause.
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
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.
"Modifying Your LOGIN File" on page 3-7 for more information about the LOGIN
file.
You can also enter these commands interactively. See COLUMN on page 13-31 for
more information.
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
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
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 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.
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. 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
To create a flat file with SQL*Plus, you first must enter the following SET
commands:
SET NEWPAGE 0
SET SPACE 0
SET LINESIZE 80
SET PAGESIZE 0
SET ECHO OFF
SET FEEDBACK OFF
SET VERIFY OFF
SET HEADING OFF
SET MARKUP HTML OFF 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 on page 13-103.
SQL*Plus stores all information displayed on the screen after you enter the SPOOL
command in the file you specify.
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.
First, use EDIT to create the script with your operating system text editor.
EDIT EMPRPT
Next, enter the following commands into the file, using your text editor:
SPOOL TEMP
CLEAR COLUMNS
CLEAR BREAKS
CLEAR COMPUTES
SET PAGESIZE 24
SET NEWPAGE 0
SET LINESIZE 70
SPOOL OFF
If you do not want to see the output on your screen, you can also add SET
TERMOUT OFF to the beginning of the file and SET TERMOUT ON to the end of
the file. Save and close the file in your text editor (you will automatically return to
SQL*Plus). Now, run the script EMPRPT:
@EMPRPT
SQL*Plus displays the output on your screen (unless you set TERMOUT to OFF),
and spools it to the file TEMP:
A C M E W I D G E T
80 Russell $14,000
Partners $13,500
********** --------------
sum $27,500
90 King $24,000
Kochhar $17,000
De Haan $17,000
********** --------------
sum $58,000
--------------
sum $98,500
COMPANY CONFIDENTIAL
6 rows selected.
This chapter explains how to generate a HTML report containing your query
results. This chapter covers the following topics:
Q Creating Reports using Command-line SQL*Plus
Q Creating Reports using iSQL*Plus
You can use SET MARKUP HTML ON SPOOL OFF to generate HTML output
suitable for embedding in an existing web page. HTML output generated this way
has no <HTML> or <BODY> tags.
Creating Reports
During a SQL*Plus session, use the SET MARKUP command interactively to write
HTML to a spool file. You can view the output in a web browser.
SET MARKUP HTML ON SPOOL ON only specifies that SQL*Plus output will be
HTML encoded, it does not create or begin writing to an output file. You must use
the SQL*Plus SPOOL command to start generation of a spool file. This file then has
HTML tags including <HTML> and </HTML>.
When creating a HTML file, it is important and convenient to specify a .html or
.htm file extension which are standard file extensions for HTML files. This enables
you to easily identify the type of your output files, and also enables web browsers
to identify and correctly display your HTML files. If no extension is specified, the
default SQL*Plus file extension is used.
You use SPOOL OFF or EXIT to append final HTML tags to the spool file and then
close it. If you enter another SPOOL filename command, the current spool file is
closed as for SPOOL OFF or EXIT, and a new HTML spool file with the specified
name is created.
You can use the SET MARKUP command to enable or disable HTML output as
required.
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
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:
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:
Q The hyphen used to continue lines in long SQL*Plus commands.
Q The TABLE option to set table WIDTH and BORDER attributes.
Q 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 >.
Q The use of quotes and concatenation characters in the SELECT statement to
create hyperlinks by concatenating string and variable elements.
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.1.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>
This example starts SQL*Plus with user "HR", 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 "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 SQLPLUS command in this example contains three layers of nested quotes.
From the inside out, these are:
Q "2" is a quoted HTML attribute value for BORDER.
Q 'BORDER="2"' is the quoted text argument for the TABLE option.
Q "HTML ON TABLE 'BORDER="2"'" is the quoted argument for the -MARKUP
option.
The nesting of quotes may be different in some operating systems or program
scripting languages.
HTML Entities
Certain characters, <, >, " and & have a predefined meaning in HTML. In the
previous example, you may have noticed that the > character was replaced by >
as soon as you entered the SET MARKUP HTML ON command. To enable these
characters to be displayed in your web browser, HTML provides character entities
to use instead.
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.
For further information about the sample schemas included with Oracle Database,
see the Oracle Database Sample Schemas guide.
Replace machine_name.domain with the host and domain names, and replace port
with the port number of your Application Server. Save the HTML file on your
Application Server.
Load the HTML file in your web browser and click "Run Employee Report".
iSQL*Plus requests your username and password. Log in to iSQL*Plus. iSQL*Plus
executes the script and displays the results in your web browser.
The name of the INPUT TYPE should be the same as either a column or substitution
variable in your script, for example
<INPUT TYPE="text" NAME="last_name" SIZE="20">
Load the HTML file in your web browser. Enter a name or partial name in the text
field, for example, "Fay". Click the Run Report button. iSQL*Plus executes the script
and displays the results in your web browser.
Example 8–5 Creating a Dynamic Script with Parameters and Login Details
Create and save the following script to a file called employee_id.sql on your
Application Server.
SET VERIFY OFF
SET PAGESIZE 200
SET MARKUP HTML ENTMAP OFF
PROMPT <H1>Employee Details for Employee Number &eid</H1>
SET MARKUP HTML ENTMAP ON
SELECT *
FROM EMPLOYEES
WHERE EMPLOYEE_ID = &eid
/
Replace machine_name.domain with the host and domain names, port with the
iSQL*Plus port number of your Application Server, and hr/your_password with a
valid userid and password. Save the HTML file on your Application Server.
Load the HTML file in your web browser. Enter an employee identification number
in the text field, for example, "105". Click the Run Report button. iSQL*Plus executes
the script and displays the results in your web browser.
This chapter provides information about how to tune SQL*Plus for better
performance. It discusses the following topics:
Q Tracing Statements
Q Collecting Timing Statistics
Q Tracing Parallel and Distributed Queries
Q SQL*Plus Script Tuning
For information about tuning Oracle Database, see the Oracle Database Performance
Tuning Guide.
Tracing Statements
You can automatically get a report on the execution path used by the SQL optimizer
and the statement execution statistics. The report is generated after successful SQL
DML (that is, SELECT, DELETE, UPDATE and INSERT) statements. It is useful for
monitoring and tuning the performance of these statements.
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 Reference.
For more information about the roles and the PLAN_TABLE, see the Oracle
Database SQL Reference and the AUTOTRACE variable of the SET command on
page 13-103.
Table created.
Role dropped.
Role created.
Grant succeeded.
Grant succeeded.
Execution Plan
The Execution Plan shows the SQL optimizer's query execution path. Each line of
the Execution Plan has a sequential line number. SQL*Plus also displays the line
number of the parent operation.
The Execution Plan consists of four columns displayed in the following order:
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
The default formats can be found in the site profile (for example, glogin.sql).
The Execution Plan output is generated using the EXPLAIN PLAN command. For
information about interpreting the output of EXPLAIN PLAN, see the Oracle
Database Performance Tuning Guide.
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 the Oracle Database Reference. For
more information about the statistics and how to interpret them, see Chapter 3,
"Gathering Optimizer Statistics" in the Oracle Database Performance Tuning Guide.
Example 9–4 Tracing Statements for Performance Statistics and Query Execution
Path
If the SQL buffer contains the following statement:
SELECT E.LAST_NAME, E.SALARY, J.JOB_TITLE
FROM EMPLOYEES E, JOBS J
WHERE E.JOB_ID=J.JOB_ID AND E.SALARY>12000;
6 rows selected.
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'EMPLOYEES'
2 1 NESTED LOOPS
3 2 TABLE ACCESS (FULL) OF 'JOBS'
4 2 INDEX (RANGE SCAN) OF 'EMP_JOB_IX' (NON-UNIQUE)
Statistics
----------------------------------------------------------
0 recursive calls
2 db block gets
34 consistent gets
0 physical reads
0 redo size
848 bytes sent through SQL*Net to client
503 bytes received through SQL*Net from client
4 SQL*Net round-trips to/from client
0 sorts (memory)
0 sorts (disk)
6 rows processed
6 rows selected.
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'EMPLOYEES'
2 1 NESTED LOOPS
3 2 TABLE ACCESS (FULL) OF 'JOBS'
4 2 INDEX (RANGE SCAN) OF 'EMP_JOB_IX' (NON-UNIQUE)
Statistics
----------------------------------------------------------
0 recursive calls
2 db block gets
34 consistent gets
0 physical reads
0 redo size
848 bytes sent through SQL*Net to client
503 bytes received through SQL*Net from client
4 SQL*Net round-trips to/from client
0 sorts (memory)
0 sorts (disk)
6 rows processed
This option is useful when you are tuning a large query, but do not want to see the
query report.
Execution Plan
-----------------------------------------------------------
0 SELECT STATEMENT (REMOTE) Optimizer=CHOOSE
1 0 TABLE ACCESS (FULL) OF 'EMPLOYEES' MY_LINK.DB_DOMAIN
The Execution Plan shows that the table being accessed on line 1 is through the
database link MY_LINK.DB_DOMAIN.
Note: Your output may vary depending on the server version and
configuration.
The format of the columns may be altered with the COLUMN command. The
default formats can be found in the site profile (for example, glogin.sql).
Table created.
Table created.
Index created.
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=26)
1 0 SORT (AGGREGATE)
2 1 SORT* (AGGREGATE) :Q2000
3 2 NESTED LOOPS* (Cost=1 Card=41 Bytes=1066) :Q2000
4 3 TABLE ACCESS* (FULL) OF 'D2_T2' (Cost=1 Card=41 Byte
:Q2000 s=533)
3 PARALLEL_COMBINED_WITH_PARENT
4 PARALLEL_COMBINED_WITH_PARENT
5 PARALLEL_COMBINED_WITH_PARENT
Line 0 of the Execution Plan shows the cost based optimizer estimates the number
of rows at 1, taking 26 bytes. The total cost of the statement is 1.
Lines 2, 3, 4 and 5 are marked with asterisks, denoting parallel operations. For
example, the NESTED LOOPS step (line 3) is a PARALLEL_TO_SERIAL operation.
PARALLEL_TO_SERIAL operations execute a SQL statement to produce output
serially. Line 2 also shows that the parallel query server had the identifier Q2000.
Numbers identifying parallel report lines cross reference the line of the parent
report. For example, in the last line of the above example:
5 PARALLEL_COMBINED_WITH_PARENT
The 5 refers to the "5 3 TABLE ACCESS*..." line in the parent report.
Statistics
----------------------------------------------------------
70 recursive calls
0 db block gets
591 consistent gets
404 physical reads
0 redo size
315 bytes sent through SQL*Net to client
850 bytes received through SQL*Net from client
3 SQL*Net round-trips to/from client
3 sorts (memory)
0 sorts (disk)
0 rows processed
If consistent gets or physical reads is 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.
COLUMN NOPRINT
COLUMN NOPRINT turns off screen output and printing of the column heading
and all values selected for the column.
It is better to remove an unneeded column from a SELECT then it is to use
COLUMN NOPRINT to stop it displaying. Removing the column from the query
means the SQL engine does not need to process it, or need to transfer the column
data back to SQL*Plus.
SET ARRAYSIZE
Sets the number of rows that SQL*Plus will fetch from the database at one time.
Valid values are 1 to 5000.
The effectiveness of setting ARRAYSIZE depends on how well Oracle Database fills
network packets and your network latency and throughput. In recent versions of
SQL*Plus and Oracle Database, ARRAYSIZE may have little effect. Overlarge sizes
can easily take more SQL*Plus memory which may decrease overall performance.
SET LINESIZE
SET LINESIZE sets the total number of characters that SQL*Plus displays on one
line before beginning a new line.
Keep LINESIZE as small as possible to avoid extra memory allocations and memory
copying.
However, if LINESIZE is too small, columns that cannot fit next to each other are
put on separate lines. This may reduce performance significantly.
SET LONGCHUNKSIZE
SET LONGCHUNKSIZE sets the size of the increments SQL*Plus uses to retrieve a
CLOB, LONG, NCLOB or XMLType value.
Experiment with different sizes if LONGS or LOBs are being fetched.
SET PAGESIZE
Sets the number of rows on each page of output in iSQL*Plus, and the number of
lines on each page of output in command-line and Windows GUI.
Increase PAGESIZE to avoid printing headings frequently, or set it to 0 to prevent
headings being displayed.
SET SERVEROUTPUT
SET SERVEROUTPUT OFF suppresses the display output (DBMS_OUTPUT.PUT_
LINE) of stored procedures or PL/SQL blocks in SQL*Plus.
Setting SERVEROUTPUT OFF stops internal SQL*Plus calls to the DBMS_OUTPUT
package done after user SQL statements.
SET SQLPROMPT
Sets the SQL*Plus command prompt.
Use the default prompt, "SQL> " to stop variable substitution occurring each time
the prompt is displayed.
SET SQLPROMPT is not supported in iSQL*Plus
SET TAB
Determines how SQL*Plus formats white space in terminal output.
Setting TAB ON causes multiple spaces to be compressed in terminal output.
Unless this significantly reduces the written data, the processing required may
marginally outweigh any benefit.
SET TAB is not supported in iSQL*Plus
SET TERMOUT
SET TERMOUT OFF suppresses the display so that you can spool output from a
script without seeing it on the screen.
If both spooling to file and writing to terminal are not required, use SET TERMOUT
OFF in SQL scripts to disable terminal output.
SET TERMOUT is not supported in iSQL*Plus
SET TRIMOUT ON
SET TRIMSPOOL ON
SET TRIMOUT ON or SET TRIMSPOOL ON removes trailing blanks at the end of
each displayed or spooled line.
Setting these variables ON can reduce the amount of data written. However, if
LINESIZE is optimal, it may be faster to set the variables OFF. The SQL*Plus output
line is blank filled throughout the query processing routines so removing the spaces
could take extra effort.
SET TRIMOUT and SET TRIMSPOOL are not supported in iSQL*Plus.
UNDEFINE
Deletes substitution variables that you defined either explicitly (with the DEFINE
command) or implicitly (with an argument to the START command or COLUMN
NEWVAL|OLDVAL).
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.
This chapter describes the available methods for controlling access to database
tables, SQL*Plus and iSQL*Plus commands, and iSQL*Plus access. It covers the
following topics:
Q PRODUCT_USER_PROFILE Table
Q Disabling SQL*Plus, SQL, and PL/SQL Commands
Q Creating and Controlling Roles
Q Disabling Commands with SQLPLUS -RESTRICT
Q Program Argument Security
Q iSQL*Plus Security
PRODUCT_USER_PROFILE Table
SQL*Plus uses the PRODUCT_USER_PROFILE (PUP) table, a table in the SYSTEM
account, to provide product-level security that supplements the user-level security
provided by the SQL GRANT and REVOKE commands and user roles.
DBAs can use the PUP table to disable certain SQL and SQL*Plus commands in the
SQL*Plus environment on a per-user basis. SQL*Plus—not Oracle
Database—enforces this security. DBAs can even restrict access to the GRANT,
REVOKE, and SET ROLE commands to control users' ability to change their
database privileges.
SQL*Plus reads restrictions from the PUP table when a user logs in to SQL*Plus and
maintains those restrictions for the duration of the session. Changes to the PUP
table will only take effect the next time the affected users log in to SQL*Plus.
Notes:
Q Disabling HOST disables the operating system alias for HOST,
such as $ on Windows, and ! on UNIX.
Q Disabling LIST disables ; and numbers (numbers entered to go
to that line in a script).
Q You must disable HELP and ? separately to disable access to
command-line help.
Q Disabling the SQL*Plus SET command also disables SQL SET
CONSTRAINTS, SET ROLE and SET TRANSACTION.
Q Disabling SQL*Plus START also disables @ and @@.
Q Disabling BEGIN and DECLARE does not prevent the use of
SQL*Plus EXECUTE to run PL/SQL. EXECUTE must be
disabled separately.
Q 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. Terminate a
Windows GUI session with File > Exit. Otherwise, terminate a
session by terminating the SQL*Plus process. If disabled, using
EXIT/QUIT to terminate the currently running script in
iSQL*Plus is also disabled. If disabled, the EXIT operation in
WHENEVER OSERROR and WHENEVER SQLERROR is also
disabled.
CONNECT HR/your_password;
SELECT * FROM EMP_DETAILS_VIEW;
4. To delete this row and remove the restriction from the user HR, CONNECT
again as SYSTEM and enter:
DELETE FROM PRODUCT_USER_PROFILE WHERE USERID = 'HR';
application roles through a PL/SQL block. This gives a SQL*Plus user only those
privileges associated with the roles enabled when they started SQL*Plus. For more
information about the creation and usage of user roles, see your Oracle Database SQL
Reference and Oracle Database Administrator's Guide.
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.
See "Disabling SET ROLE" on page 10-7 for more information.
To re-enable roles, delete the row containing the restriction.
Notes:
Q Disabling HOST also disables your operating system's alias for
HOST, such as $ on Windows, and ! on UNIX.
Q 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 on page 4-23.
Q 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.
Any file on your computer storing a username and password needs to be secured
from non-authorized access.
iSQL*Plus Security
There are two main areas to consider for security and user authentication when
using iSQL*Plus:
Q The HTTP protocol connection between the web browser and the Application
Server.
Q The Oracle Net connection between the Application Server and Oracle
Database.
It is useful to note that in iSQL*Plus you cannot access the middle tier operating
system to run commands such as HOST, EDIT and SPOOL which depend on
operating system access.
In iSQL*Plus, security for the connection between the web browser and the
Application Server is provided by standard HTTPS. It enables secure listener
connections with an Oracle Database-provided encryption mechanism through the
Secure Sockets Layer (SSL).
The Oracle Net connection between the iSQL*Plus Server and Oracle Database
provides the same security as in previous client server architectures. It is
recommended that you enable an Oracle Net listener password if possible. For more
information about Oracle Net connection security, see the Oracle Net Services
Administrator's Guide and the Oracle Advanced Security Administrator’s Guide.
Administration Privileges
There are two modes of access to iSQL*Plus:
Q Connect as a normal user.
Requires an Oracle Database account username and password entered in the
iSQL*Plus Login screen.
Q Connect as a SYSDBA or SYSOPER privileged user.
Requires an Oracle Database account username and password entered in the
iSQL*Plus DBA Login screen, and an Application Server authentication
username and password entered in a separate dialog.
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 Chapter 10,
"SQL*Plus Security".
Database Startup
Starting a database involves three steps:
1. Starting an instance
An instance controls the background processes and the allocation of memory
area to access an Oracle database.
2. Mounting the database
Mounting the database associates it with a previously started instance.
3. Opening the database
Opening the database makes it available for normal database operations.
For more information about database startup, see the Oracle Database Concepts
guide. For more information about starting a database, see the STARTUP command
on page 13-148.
where SALES is the database name specified in the DB_NAME parameter in the
INITSALES.ORA parameter file.
where SALES is the database name specified in the DB_NAME parameter in the
INITSALES.ORA parameter file.
Database Shutdown
Shutting down a database involves three steps:
1. Closing the database
When a database is closed, all database and recovery data in the SGA are
written to the datafiles and redo log files, and all online datafiles are closed.
2. Dismounting the database
Dismounting the database disassociates the database from an instance and
closes the control files of the database.
3. Shutting down the instance
Shutting down an instance reclaims the SGA from memory and terminates the
background Oracle Database processes that constitute an Oracle Database
instance.
For more information about database shutdown, see the Oracle Database Concepts
guide. For information about stopping a database, see the SHUTDOWN command
on page 13-142.
Database closed.
Database dismounted.
ORACLE instance shut down.
ARCHIVELOG Mode
Operating a database in ARCHIVELOG mode enables the archiving of the online
redo log.
The ARCHIVE LOG 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
Oracle Database Concepts manual, and the ARCHIVE LOG command on page 13-14.
To automatically begin archiving, enter
ARCHIVE LOG START
To list the details of the current log file being archived, enter
ARCHIVE LOG LIST
Database Recovery
If a damaged database is in ARCHIVELOG mode, it is a candidate for either
complete media recovery or incomplete media recovery operations. To begin media
recovery operations use the RECOVER command. For more information about
recovering data, see the RECOVER command on page 13-85.
Because of possible network timeouts, it is recommended that you use SQL*Plus
command-line, not iSQL*Plus, for long running DBA operations such as RECOVER.
In order to begin recovery operations, you must have DBA privileges.
To recover the database up to a specified time using a control backup file, enter
RECOVER DATABASE UNTIL TIME '1998-11-23:12:47:30'-
USING BACKUP CONTROLFILE
Make sure that the tablespaces you are interested in recovering have been taken
offline, before proceeding with recovery for those tablespaces.
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:
Q Configuring Globalization Support in Command-line SQL*Plus
Q Configuring Multiple Language Support in iSQL*Plus
Q NLS_LANG Environment Variable
For more information on globalization support, see the Oracle Technology Network
globalization notes at http://otn.oracle.com/tech/globalization/, and see the
Oracle Database Globalization Support Guide
SQL*Plus Client
The SQL*Plus client environment is configured by setting the NLS_LANG
environment variable which is read by SQL*Plus at startup.
Oracle Database
The Oracle Database environment is configured by creating the database with the
required character set.
Web Browser
No changes are necessary to have multilingual support in your iSQL*Plus web
browser. However, your browser must support UTF-8 character encoding. Most
current web browsers support UTF-8.
The character encoding in the iSQL*Plus browser is set to UTF-8 by the charset
attribute in the header of HTML pages returned from the iSQL*Plus Application
Server.
Application Server
The language and territory values of the NLS_LANG environment variable in effect
when the iSQL*Plus Application Server starts specifies behavior for the iSQL*Plus
Application Server. The character set value is ignored.
The language and territory values set for an application server are used for all
iSQL*Plus sessions run from that application server. However, you can use an
ALTER SESSION command to change the language and territory used for the
duration of the current session. For example, to use Chinese language and
conventions in your current session, enter
ALTER SESSION SET NLS_LANGUAGE='SIMPLIFIED CHINESE';
ALTER SESSION SET NLS_TERRITORY='CHINA';
New pages served to your iSQL*Plus browser are now displayed with error
messages and text fields in Chinese. Information is now displayed according to
Chinese convention. This is a temporary change for the current login in the current
iSQL*Plus session. To check what settings are currently in effect, enter:
SELECT * FROM NLS_SESSION_PARAMETERS;
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
charset is not used by the iSQL*Plus Application Server. The iSQL*Plus Application
Server always uses AL32UTF8 character encoding, Oracle's implementation of
Unicode. It cannot be changed.
Setting NLS_LANG
You can set the NLS_LANG environment variable to control globalization features.
This section contains the SQL*Plus command reference, and the list of SQL*Plus
error messages.
The following chapters are covered in this section:
Q SQL*Plus Command Reference
Q SQL*Plus Error Messages
13
SQL*Plus Command Reference
Section Description
Syntax Shows how to enter the command and provides a brief
description of the basic uses of the command.
See "Conventions" on page -xxiv for an explanation of the syntax
notation
Terms Describes the function of each term or clause appearing in the
syntax.
Usage Provides additional information on uses of the command and on
how the command works.
Examples Gives one or more examples of the command.
A summary table that lists and briefly describes SQL*Plus commands precedes the
individual command descriptions.
You can continue a long SQL*Plus command by typing a hyphen at the end of the
line and pressing Return. If you wish, you can type a space before typing the
hyphen. SQL*Plus displays a right angle-bracket (>) as a prompt for each additional
line.
You do not need to end a SQL*Plus command with a semicolon. When you finish
entering the command, you can press Return. If you wish, however, you can enter a
semicolon at the end of a SQL*Plus command.
*APPEND on Adds specified text to the end of the current line in the
page 13-13 buffer.
ARCHIVE LOG on Starts or stops the automatic archiving of online redo log
page 13-14 files, manually (explicitly) archives specified redo log files,
or displays information about redo log files.
ATTRIBUTE on Specifies display characteristics for a given attribute of an
page 13-17 Object Type column, and lists the current display
characteristics for a single attribute or all attributes.
BREAK on Specifies where and how formatting will change in a report,
page 13-19 or lists the current break definition.
CLEAR on Resets or erases the current clause or setting for the specified
page 13-29 option, such as BREAKS or COLUMNS.
COLUMN on Specifies display characteristics for a given column, or lists
page 13-31 the current display characteristics for a single column or for
all columns.
DESCRIBE on Lists the column definitions for the specified table, view, or
page 13-59 synonym or the specifications for the specified function or
procedure.
PAUSE on Displays the specified text, then waits for the user to press
page 13-82 Return.
PRINT on Displays the current value of a bind variable.
page 13-83
TTITLE on Places and formats a specified title at the top of each report
page 13-155 page, or lists the current TTITLE definition.
@ ("at" sign)
Syntax
@{url | file_name [.ext] } [arg ...]
Runs the SQL*Plus statements in the specified script. The script can be called from
the local file system or from a web server. Only the url form is supported in
iSQL*Plus. The @ command functions similarly to 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} on page 13-133.
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 "Substitution Variables in iSQL*Plus" on page 6-24.
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" on page 10-4), this will also disable the @ command. See START on
page 13-146 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} on
page 13-133 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
Syntax
@@url | file_name[.ext]
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. Only the url form is supported in iSQL*Plus. The @@ command
functions similarly to START.
Terms
url
Specifies the Uniform Resource Locator of a script to run on the specified web
server. SQL*Plus supports HTTP and FTP protocols, but not HTTPS. HTTP
authentication in the form http://username:password@machine_name.domain... is not
supported in this release.
file_name[.ext]
Represents the nested script you wish to run. If you omit ext, SQL*Plus assumes the
default command-file extension (normally SQL). For information on changing the
default extension, see SET SUF[FIX] {SQL | text} on page 13-133.
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.
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" on page 10-4), this will also disable the @@ command. For more
information, see the SPOOL command on page 13-144.
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} on page 13-133 for more
information.
Examples
Suppose that you have the following script named PRINTRPT:
SELECT DEPARTMENT_ID, CITY FROM EMP_DETAILS_VIEW WHERE SALARY>12000;
@EMPRPT.SQL
@@ WKRPT.SQL
When you START PRINTRPT and it reaches the @ command, it looks for the script
named EMPRPT in the current working directory and runs it. When PRINTRPT
reaches the @@ command, it looks for the script named WKRPT in the same path as
PRINTRPT and runs it.
Suppose that the same script PRINTRPT was located on a web server and you ran it
with START HTTP://machine_name.domain:port/PRINTRPT. When it reaches the @
command, it looks for the script named EMPRPT in the current working directory
and runs it. When PRINTRPT reaches the @@ command, it looks for the script
named WKRPT in the same url as PRINTRPT,
HTTP://machine_name.domain:port/WKRPT.SQL and runs it.
/ (slash)
Syntax
/(slash)
Executes the most recently executed SQL command or PL/SQL block which is
stored in the SQL buffer.
The buffer has no command history list and does not record SQL*Plus commands.
Usage
You can enter a slash (/) at the command prompt or at a line number prompt of a
multi-line command, or in the input area of the iSQL*Plus Workspace.
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_NAME
FROM EMP_DETAILS_VIEW
WHERE SALARY=12000;
CITY COUNTRY_NAME
------------------------------ ----------------------------------------
Seattle United States of America
Oxford United Kingdom
Seattle United States of America
ACCEPT
Syntax
ACC[EPT] variable [NUM[BER] | CHAR | DATE | BINARY_FLOAT | BINARY_DOUBLE] [FOR[MAT]
format] [DEF[AULT] default] [PROMPT text|NOPR[OMPT]] [HIDE]
Reads a line of input and stores it in a given substitution variable.
In iSQL*Plus, displays the Input Required screen for you to enter a value for the
substitution variable.
Terms
variable
Represents the name of the variable in which you wish to store a value. If variable
does not exist, SQL*Plus creates it.
NUM[BER]
Makes the variable a NUMBER datatype. If the reply does not match the datatype,
ACCEPT gives an error message and prompts again.
CHAR
Makes the variable a CHAR datatype. The maximum CHAR length is 240 bytes. If a
multi-byte character set is used, one CHAR may be more than one byte in size.
DATE
Makes reply a valid DATE format. If the reply is not a valid DATE format, ACCEPT
gives an error message and prompts again. The datatype is CHAR.
BINARY_FLOAT
Makes the variable a BINARY_FLOAT datatype.
BINARY_DOUBLE
Makes the variable a BINARY_DOUBLE datatype.
FOR[MAT]
Specifies the input format for the reply. If the reply does not match the specified
format, ACCEPT gives an error message and prompts again. If an attempt is made
to enter more characters than are specified by the char format, an error message is
given and the value must be reentered. If an attempt is made to enter a greater
number precision than is specified by the number format, an error message is given
and the value must be reentered. The format element must be a text constant such
as A10 or 9.999. See COLUMN FORMAT on page 13-31 for a complete list of format
elements.
Oracle Database date formats such as "dd/mm/yy" are valid when the datatype is
DATE. DATE without a specified format defaults to the NLS_DATE_FORMAT of
the current session. See the Oracle Database Administrator's Guide and the Oracle
Database SQL Reference for information on Oracle Database date formats.
DEF[AULT]
Sets the default value if a reply is not given. The reply must be in the specified
format if defined.
PROMPT text
Displays text on-screen before accepting the value of variable from the user.
NOPR[OMPT]
Skips a line and waits for input without displaying a prompt.
ACCEPT NOPR[OMPT] is not applicable in iSQL*Plus.
HIDE
Suppresses the display as you type the reply.
To display or reference variables, use the DEFINE command. See the DEFINE
command on page 13-51 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: '
APPEND
Syntax
A[PPEND] text
where text represents the text to append.
Adds specified text to the end of the current line in the SQL buffer. The buffer has
no command history list and does not record SQL*Plus commands.
To separate text from the preceding characters with a space, enter two spaces
between APPEND and text.
To APPEND text that ends with a semicolon, end the command with two
semicolons (SQL*Plus interprets a single semicolon as an optional command
terminator).
Examples
To append a comma delimiter, a space and the column name CITY to the first line
of the buffer, make that line the current line by listing the line as follows:
1
1* SELECT DEPARTMENT_ID
SQL*Plus appends the first semicolon to the line and interprets the second as the
terminator for the APPEND command.
ARCHIVE LOG
Syntax
ARCHIVE LOG {LIST | STOP} | {START | NEXT | ALL | integer } [TO destination]
Starts or stops automatic archiving of online redo log files, manually (explicitly)
archives specified redo log files, or displays information about redo log files.
Terms
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.
STOP
Disables automatic archival. If the instance is still in ARCHIVELOG mode and all
redo log file groups fill, database operation is suspended until a redo log file is
archived (for example, until you enter the command ARCHIVE LOG NEXT or
ARCHIVE LOG ALL).
START
Enables automatic archiving. Starts the background process ARCH, which performs
automatic archiving as required. If ARCH is started and a filename is supplied, the
filename becomes the new default archive destination. ARCH automatically starts
on instance startup if the initialization parameter LOG_ARCHIVE_START is set to
TRUE.
NEXT
Manually archives the next online redo log file group that has been filled, but not
yet archived.
ALL
Manually archives all filled, but not yet archived, online redo log file groups.
integer
Causes archival of the online redo log file group with log sequence number n. You
can specify any redo log file group that is still online. An error occurs if the log file
cannot be found online or the sequence number is not valid. This option can be
used to re-archive a log file group.
destination
Specifies the destination device or directory in an operating system. Specification of
archive destination devices is installation-specific; see your platform-specific Oracle
Database documentation for examples of specifying archive destinations. On many
operating systems, multiple log files can be spooled to the same tape.
If not specified in the command-line, the archive destination is derived from the
initialization parameter LOG_ARCHIVE_DEST. The command ARCHIVE LOG
START destination causes the specified device or directory to become the new
default archive destination for all future automatic or manual archives. A
destination specified with any other option is a temporary destination that is in
effect only for the current (manual) archive. It does not change the default archive
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 on
page 13-48.
If an online redo log file group fills and none are available for reuse, database
operation is suspended. The condition can be resolved by archiving a log file group.
For information about specifying archive destinations, see your platform-specific
Oracle Database documentation.
Examples
To start up the archiver process and begin automatic archiving, using the archive
destination specified in LOG_ARCHIVE_DEST, enter
ARCHIVE LOG START
To archive the log file group with sequence number 1001 to the destination
specified, enter
ARCHIVE LOG 1001 '/vobs/oracle/dbs/arch'
'arch' specifies the prefix of the filename on the destination device; the remainder of
the filename is dependent on the initialization parameter
LOG_ARCHIVE_FORMAT, which specifies the filename format for archived redo
log files.
ATTRIBUTE
Syntax
ATTRIBUTE [type_name.attribute_name [option ...]]
where option represents one of the following clauses:
ALI[AS] alias
CLE[AR]
FOR[MAT] format
LIKE {type_name.attribute_name | alias}
ON | OFF
Specifies display characteristics for a given attribute of an Object Type column, such
as 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
Assigns a specified alias to a type_name.attribute_name, which can be used to refer to
the type_name.attribute_name in other ATTRIBUTE commands.
CLE[AR]
Resets the display characteristics for the attribute_name. The format specification
must be a text constant such as A10 or $9,999—not a variable.
FOR[MAT] format
Specifies the display format of the column. The format specification must be a text
constant such as A10 or $9,999—not a variable.
LIKE {type_name.attribute_name | alias}
Copies the display characteristics of another attribute. LIKE copies only
characteristics not defined by another clause in the current ATTRIBUTE command.
ON | OFF
Controls the status of display characteristics for a column. OFF disables the
characteristics for an attribute without affecting the characteristics' definition. ON
reinstates the characteristics.
Usage
You can enter any number of ATTRIBUTE commands for one or more attributes.
All attribute characteristics set for each attribute remain in effect for the remainder
of the session, until you turn the attribute OFF, or until you use the CLEAR
COLUMN command. Thus, the ATTRIBUTE commands you enter can control an
attribute's display characteristics for multiple SQL SELECT commands.
When you enter multiple ATTRIBUTE commands for the same attribute, SQL*Plus
applies their clauses collectively. If several ATTRIBUTE commands apply the same
clause to the same attribute, the last one entered will control the output.
Examples
To make the LAST_NAME attribute of the Object Type EMPLOYEE_TYPE 20
characters wide, enter
ATTRIBUTE EMPLOYEE_TYPE.LAST_NAME FORMAT A20
BREAK
Syntax
BRE[AK] [ON report_element [action [action]]] ...
where report_element has the syntax {column|expr|ROW|REPORT}
and action has the syntax [SKI[P] n|[SKI[P]] PAGE]
[NODUP[LICATES]|DUP[LICATES]]
Specifies where changes occur in a report and the formatting action to perform,
such as:
Q suppressing display of duplicate values for a given column
Q skipping a line each time a given column value changes
(In iSQL*Plus, only when Preformatted Output is ON)
Q printing computed figures each time a given column value changes or at the
end of the report.
See the COMPUTE command on page 13-42.
Enter BREAK with no clauses to list the current BREAK definition.
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.
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 or in iSQL*Plus unless PREFORMAT
is SET ON.
[SKI[P]] PAGE
Skips the number of lines that are defined to be a page before printing the row
where the break occurred. The number of lines per page can be set 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.
DUP[LICATES]
Prints the value of a break column in every selected row.
Enter BREAK with no clauses to list the current break definition.
Usage
Each new BREAK command you enter replaces the preceding one.
To remove the BREAK command, use CLEAR BREAKS.
Examples
To produce a report that prints duplicate job values, prints the average of SALARY,
and 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
************* ----------
sum 61000
25 rows selected.
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) on page C-2.
Terms
Refer to the TTITLE command on page 13-155 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.
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'
CHANGE
Syntax
C[HANGE] sepchar old [sepchar [new [sepchar]]]
Changes the first occurrence of the specified text on the current line in the buffer.
The buffer has no command history list and does not record SQL*Plus commands.
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.
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/
2* C/OLD/NEW/
CLEAR
Syntax
CL[EAR] option ...
where option represents one of the following clauses:
BRE[AKS]
BUFF[ER]
COL[UMNS]
COMP[UTES]
SCR[EEN]
SQL
TIMI[NG]
Resets or erases the current value or setting for the specified option.
CLEAR SCREEN command not available in iSQL*Plus.
Terms
BRE[AKS]
Removes the break definition set by the BREAK command.
BUFF[ER]
Clears text from the buffer. CLEAR BUFFER has the same effect as CLEAR SQL,
unless you are using multiple buffers.
See SET BUF[FER] {buffer|SQL} (obsolete) on page C-3 for more information about
the obsolete form of this command.
COL[UMNS]
Resets column display attributes set by the COLUMN command to default settings
for all columns. To reset display attributes for a single column, use the CLEAR
clause of the COLUMN command. CLEAR COLUMNS also clears the ATTRIBUTEs
for that column.
COMP[UTES]
Removes all COMPUTE definitions set by the COMPUTE command.
SCR[EEN]
Clears your screen.
CLEAR SCREEN is not available in iSQL*Plus.
SQL
Clears the text from SQL buffer. CLEAR SQL has the same effect as CLEAR
BUFFER, unless you are using multiple buffers.
See SET BUF[FER] {buffer|SQL} (obsolete) on page C-3 for more information about
the obsolete form of this command.
TIMI[NG]
Deletes all timers created by the TIMING command.
Examples
To clear breaks, enter
CLEAR BREAKS
COLUMN
Syntax
COL[UMN] [{column | expr} [option ...]]
where option represents one of the following clauses:
ALI[AS] alias
CLE[AR]
ENTMAP {ON | OFF}
FOLD_A[FTER]
FOLD_B[EFORE]
FOR[MAT] format
HEA[DING] text
JUS[TIFY] {L[EFT] | C[ENTER] | R[IGHT]}
LIKE {expr | alias}
NEWL[INE]
NEW_V[ALUE] variable
NOPRI[NT] | PRI[NT]
NUL[L] text
OLD_V[ALUE] variable
ON | OFF
WRA[PPED] | WOR[D_WRAPPED] | TRU[NCATED]
Specifies display attributes for a given column, such as
Q text for the column heading
Q alignment of the column heading
Q format for NUMBER data
Q wrapping of column data
Also lists the current display attributes for a single column or all columns.
Enter COLUMN followed by column or expr and no other clauses to list the current
display attributes for only the specified column or expression. Enter COLUMN with
no clauses to list all current column display attributes.
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]
Resets the display attributes for the column to default values.
To reset the attributes for all columns, use the CLEAR COLUMNS command.
CLEAR COLUMNS also clears the ATTRIBUTEs for that column.
ENTMAP {ON | OFF}
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" on page 4-19.
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 or
in iSQL*Plus 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
or in iSQL*Plus 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.
DATE Columns 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 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.
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.
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'
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 or in iSQL*Plus 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 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 on page 13-155 command later in this chapter. 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 on
page 13-155 command later in this chapter.
ON | OFF
Controls the status of display attributes for a column. OFF disables the attributes for
a column without affecting the attributes' definition. ON reinstates the attributes.
WRA[PPED] | WOR[D_WRAPPED] | TRU[NCATED]
Specifies how SQL*Plus will treat a datatype or DATE string that is too wide for a
column. WRAPPED wraps the string within the column bounds, beginning new
lines when required. When WORD_WRAP is enabled, SQL*Plus left justifies each
new line, skipping all leading whitespace (for example, returns, newline characters,
tabs and spaces), including embedded newline characters. Embedded whitespace
not on a line boundary is not skipped. TRUNCATED truncates the string at the end
of the first line of display.
Usage
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
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 "Displaying the Current Date in Titles"
on page 7-32.
Your two page report would look similar to the following report, with "Job Report"
centered within your current linesize:
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
See the Oracle Database SQL Reference for information on the ALTER SESSION
command.
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 "Clarifying
Your Report with Spacing and Summary Lines" on page 7-12.
Terms
function ...
Represents one of the functions listed in Table 13–2, "COMPUTE Functions". 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 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:
Q One or more of the expressions, columns, or column aliases you reference in the
OF clause must also be in the SELECT command.
Q 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.
Q 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;
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;
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.
CONNECT
Syntax
CONN[ECT] { logon | / } [AS {SYSOPER | SYSDBA}]
where logon has the syntax username[/password] [@connect_identifier]
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.
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)" on page 13-10 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 on page 13-81 for information about changing your
password in SQL*Plus, and see "Changing Your Password in iSQL*Plus" on
page 4-2 for information about changing passwords in iSQL*Plus.
connect_identifier
An Oracle Net connect identifier. The exact syntax depends on the Oracle Net
communications protocol your Oracle Database installation uses. For more
information, refer to the Oracle Net manual for your protocol or contact your DBA.
SQL*Plus does not prompt for a service name, but uses your default database if you
do not include a connect identifier.
/ (slash)
Represents a default logon using operating system authentication. You cannot enter
a connect_identifier if you use a default logon. In a default logon, SQL*Plus
typically attempts to log you in using the username OPS$name, where name is your
operating system username. See the Oracle Database Administrator's Guide for
information about operating system authentication.
AS {SYSOPER | SYSDBA}
The AS clause enables privileged connections by users who have been granted
SYSOPER or SYSDBA system privileges. You can use either of these privileged
connections with the default logon, /.
For information about system privileges, see the 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
Reference.
Examples
To connect across Oracle Net with username HR and password HR to the database
known by the Oracle Net alias as FLEETDB, enter
CONNECT HR/your_password@FLEETDB
To connect as user HR, letting SQL*Plus prompt you for the password, enter
CONNECT HR
For more information about setting up your password file, refer to the Oracle
Database Administrator's Guide.
To use a password file to connect to an instance on the current node as a privileged
user named HR with the password HR, enter
CONNECT HR/your_password AS SYSDBA
COPY
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
Defines (names) a substitution variable and assigns it a CHAR value.
Enter DEFINE followed by variable to list the value and type of variable. Enter
DEFINE with no clauses to list the values and types of all substitution variables.
Usage
Defined variables retain their values until you:
Q enter a new DEFINE command referencing the variable
Q enter an UNDEFINE command referencing the variable
Q enter an ACCEPT command referencing the variable
Q reference the variable in the NEW_VALUE or OLD_VALUE clause of a
COLUMN command and then reference the column in a SELECT command
Q 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
Predefined Variables
There are eight variables defined during SQL*Plus installation. These variables only
differ from user defined variables by having predefined values.
_CONNECT_IDENTIFIER
Contains the connection identifier as supplied by the user to make a connection
where it is available.
_DATE
Contains the current date, or a fixed string. _DATE can be either dynamic, showing
the current date which is the default, or it can be set to a fixed string. The current
date 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.
User's 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.
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 10g Release 10.1.0.2.0 - Production
_O_RELEASE
Contains the full release number of the installed Oracle Database in the form:
101020000
_PRIVILEGE
Contains a value indicating the privilege level of the current connection. It contains
one of the following values:
Q AS SYSDBA
Q AS SYSOPER
_SQLPLUS_RELEASE
Contains the full release number of the installed SQL*Plus component in the form:
101020000
_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.
You can use the DEFINE command to view the definitions of these eight 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.
DEL
Syntax
DEL [n | n m | n * | n LAST | * | * n | * LAST | LAST]
Deletes one or more lines of the buffer.
SQL*Plus commands are not stored in the buffer. There is no history of commands
previously entered in the buffer.
Terms
Term Description
n Deletes line 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.
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
DESCRIBE
Syntax
DESC[RIBE] {[schema .]object[@connect_identifier]}
Lists the column definitions for the specified table, view or synonym, or the
specifications for the specified function or procedure.
Terms
schema
Represents the schema where the object resides. If you omit schema, SQL*Plus
assumes you own object.
object
Represents the table, view, type, procedure, function, package or synonym you
wish to describe.
@connect_identifier
Consists of the database link name corresponding to the database where object
exists. For more information on which privileges allow access to another table in a
different schema, refer to the Oracle Database SQL Reference.
Usage
The description for tables, views, types and synonyms contains the following
information:
Q each column's name
Q whether or not null values are allowed (NULL or NOT NULL) for each column
Q datatype of columns, for example, CHAR, DATE, LONG, LONGRAW,
NUMBER, RAW, ROWID, VARCHAR2 (VARCHAR), or XMLType
Q 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 later in this chapter.
To control the width of the data displayed, use the SET LINESIZE command.
Columns output for the DESCRIBE command are typically allocated a proportion of
the linesize currently specified. Decreasing or increasing the linesize with the SET
LINESIZE command usually makes each column proportionally smaller or larger.
This may give unexpected text wrapping in your display. For more information, see
the SET command later in this chapter.
The description for functions and procedures contains the following information:
Q the type of PL/SQL object (function or procedure)
Q the name of the function or procedure
Q the type of value returned (for functions)
Q the argument names, types, whether input or output, and default values, if any
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
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
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) );
/
CREATE OR REPLACE TYPE BODY rational AS OBJECT
MAP MEMBER FUNCTION rational_order -
RETURN DOUBLE PRECISION IS
BEGIN
RETURN NUMERATOR/DENOMINATOR;
END;
END;
/
DESCRIBE rational
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
For more information on using the CREATE TYPE command, see your Oracle
Database SQL Reference.
For information about using the SET DESCRIBE and SHOW DESCRIBE commands,
see the SET command on page 13-103 and SHOW command on page 13-136.
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. In iSQL*Plus, click the Logout
button to log out of Oracle Database.
Examples
Your script might begin with a CONNECT command and end with a
DISCONNECT, as shown later.
CONNECT HR/your_password
SELECT LAST_NAME, DEPARTMENT_NAME FROM EMP_DETAILS_VIEW;
DISCONNECT
SET INSTANCE FIN2
CONNECT HR2/your_password
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. The buffer has no command history list and does not
record SQL*Plus commands.
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 in this chapter.
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 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 on
page 13-51. 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 in this chapter.
If you do not specify a filename and the buffer is empty, EDIT returns an error
message.
To leave the editing session and return to SQL*Plus, terminate the editing session in
the way customary for the text editor. When you leave the editor, SQL*Plus loads
the contents of the file into the buffer.
Examples
To edit the file REPORT with the extension SQL using your operating system text
editor, enter
EDIT REPORT
EXECUTE
Syntax
EXEC[UTE] statement
where statement represents a PL/SQL statement.
Executes a single PL/SQL statement. The EXECUTE command is often useful when
you want to execute a PL/SQL statement that references a stored procedure. For
more information on PL/SQL, see your PL/SQL User's Guide and Reference.
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 on
page 13-160.
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.
In iSQL*Plus, commits or rolls back all pending changes, stops processing the
current iSQL*Plus script and returns focus to the Input area. There is no way to
access the return code in iSQL*Plus. In iSQL*Plus click the Logout button to exit the
Oracle Database.
Commit on exit, or commit on termination of processing in iSQL*Plus, is performed
regardless of the status of SET AUTOCOMMIT.
Terms
{EXIT | QUIT}
Can be used interchangeably (QUIT is a synonym for EXIT).
SUCCESS
Exits normally.
FAILURE
Exits with a return code indicating failure.
WARNING
Exits with a return code indicating warning.
COMMIT
Saves pending changes to the database before exiting.
n
Represents an integer you specify as the return code.
variable
Represents a user-defined or system variable (but not a bind variable), such as
SQL.SQLCODE. EXIT variable exits with the value of variable as the return code.
:BindVariable
Represents a variable created in SQL*Plus with the VARIABLE command, and then
referenced in PL/SQL, or other subprograms. :BindVariable exits the subprogram
and returns you to SQL*Plus.
ROLLBACK
Executes a ROLLBACK statement and abandons pending changes to the database
before exiting.
EXIT with no clauses commits and exits with a value of SUCCESS.
Usage
EXIT 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
command on page 13-170 and WHENEVER OSERROR command on page 13-168.
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
GET
Syntax
GET [FILE] file_name[.ext] [LIS[T] | NOL[IST]]
Loads an operating system file into the SQL buffer.
In iSQL*Plus click the Load Script button to load a script into the Input area.
The buffer has no command history list and does not record SQL*Plus commands.
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]
Represents the file you wish to load (typically a script).
LIS[T]
Lists the contents of the file after it is loaded. This is the default.
NOL[IST]
Suppresses the listing.
Usage
If you do not specify a file extension, SQL*Plus assumes the default command-file
extension (normally SQL). For information on changing the default extension, see
SET SUF[FIX] {SQL | text} on page 13-133.
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 on page 13-101 for more information.
Examples
To load a file called YEARENDRPT with the extension SQL into the buffer, enter
GET YEARENDRPT
HELP
Syntax
HELP | ? [topic]
where topic represents a SQL*Plus help topic, for example, COLUMN.
Accesses the SQL*Plus command-line help system. Enter HELP INDEX or ? INDEX
for a list of topics. You can view SQL*Plus resources at
http://otn.oracle.com/tech/sql_plus/ and the Oracle Database Library at
http://otn.oracle.com/documentation/.
In iSQL*Plus, click the Help icon to access the iSQL*Plus Online Help.
Enter HELP or ? without topic to get help on the help system.
Usage
You can only enter one topic after HELP. You can abbreviate the topic (for example,
COL for COLUMN). However, if you enter only an abbreviated topic and the
abbreviation is ambiguous, SQL*Plus displays help for all topics that match the
abbreviation. For example, if you enter
HELP EX
SQL*Plus displays the syntax for the EXECUTE command followed by the syntax
for the EXIT command.
If you get a response indicating that help is not available, consult your database
administrator.
Examples
To see a list of SQL*Plus commands for which help is available, enter
HELP INDEX
or
? INDEX
To see a single column list of SQL*Plus commands for which help is available, enter
HELP TOPICS
HOST
Syntax
HO[ST] [command]
where command represents an operating system command.
Executes an operating system command without leaving SQL*Plus.
Enter HOST without command to display an operating system prompt. You can then
enter multiple operating system commands. For information on returning to
SQL*Plus, refer to the platform-specific Oracle documentation provided for your
operating system.
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} on
page 13-133 for more information.
Examples
To execute a UNIX operating system command, ls *.sql, enter
HOST ls *.sql
INPUT
Syntax
I[NPUT] [text]
where text represents the text you wish to add.
Adds one or more new lines of text after the current line in the buffer. The buffer
has no command history list and does not record SQL*Plus commands.
To add a single line, enter the text of the line after the command INPUT, separating
the text from the command with a space. To begin the line with one or more spaces,
enter two or more spaces between INPUT and the first non-blank character of text.
To add several lines, enter INPUT with no text. INPUT prompts you for each line.
To leave INPUT, enter a null (empty) line or a period.
Usage
If you enter a line number at the command prompt larger than the number of lines
in the buffer, and follow the number with text, SQL*Plus adds the text in a new line
at the end of the buffer. If you specify zero (0) for the line number and follow the
zero with text, then SQL*Plus inserts the line at the beginning of the buffer (that line
becomes line 1).
Examples
Assume the SQL buffer contains the following command:
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:
2* FROM EMP_DETAILS_VIEW
INPUT
3 WHERE JOB_ID = 'SA_MAN'
4 AND COMMISSION_PCT=.25
5
INPUT prompts you for new lines until you enter an empty line or a period. The
SQL buffer now contains the following lines:
LIST
Syntax
L[IST] [n | n m | n * | n LAST | * | * n | * LAST | LAST]
Lists one or more lines of the SQL buffer.
The buffer has no command history list and does not record SQL*Plus commands.
In SQL*Plus command-line you can also use ";" to list all the lines in the SQL buffer.
Terms
Term Description
n Lists line 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
;
2* FROM EMP_DETAILS_VIEW
To list the current line (now line 2) to the last line, enter
LIST * LAST
2 FROM EMP_DETAILS_VIEW
3 WHERE JOB_ID = 'SH_CLERK'
4* ORDER BY DEPARTMENT_ID
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. In
iSQL*Plus, use the Password screen to change your password.
Usage
To change the password of another user, you must have been granted the
appropriate privilege. See CONNECT on page 13-48 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.
PAUSE
Syntax
PAU[SE] [text]
where text represents the text you wish to display.
Displays the specified text then waits for the user to press RETURN.
In iSQL*Plus, displays the Next Page button which the user must click to continue.
Enter PAUSE followed by no text to display two empty lines.
Usage
Because PAUSE always waits for the user's response, it is best to use a message that
tells the user explicitly to press [Return].
PAUSE reads input from the terminal (if a terminal is available) even when you
have designated the source of the command input as a file.
See SET PAU[SE] {ON | OFF | text} on page 13-125 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 ...
Syntax
PRI[NT] [variable ...]
where variable ... represents names of bind variables whose values you want to
display.
Displays the current values of bind variables. For more information on bind
variables, see your PL/SQL User's Guide and Reference.
Enter PRINT with no variables to print all bind variables.
Usage
Bind variables are created using the VARIABLE command. See VARIABLE on
page 13-160 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 Chapter 7,
"Formatting SQL*Plus Reports".
To automatically display bind variables referenced in a successful PL/SQL block or
used in an EXECUTE command, use the AUTOPRINT clause of the SET command.
See SET on page 13-103 for more information.
Examples
The following example illustrates a PRINT command:
VARIABLE n NUMBER
BEGIN
:n := 1;
END;
/
PRINT n
N
----------
1
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:
PROMPT
PROMPT Please enter a valid department
PROMPT For example: 10
SELECT DEPARTMENT_NAME FROM EMP_DETAILS_VIEW
WHERE 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.
RECOVER
Syntax
RECOVER {general | managed | BEGIN BACKUP | END BACKUP}
where the general clause has the following syntax:
[AUTOMATIC] [FROM location]
{ {full_database_recovery | partial_database_recovery | LOGFILE filename}
[ {TEST | ALLOW integer CORRUPTION | parallel_clause } [TEST | ALLOW integer CORRUPTION |
parallel_clause ]...]
| CONTINUE [DEFAULT] | CANCEL}
where the full_database_recovery clause has the following syntax:
[STANDBY] DATABASE
[ {UNTIL {CANCEL | TIME date | CHANGE integer} | USING BACKUP CONTROLFILE}
[UNTIL {CANCEL | TIME date | CHANGE integer} | USING BACKUP CONTROLFILE]...]
where the partial_database_recovery clause has the following syntax:
{TABLESPACE tablespace [, tablespace]...
| DATAFILE {filename | filenumber} [, filename | filenumber]...
| STANDBY {TABLESPACE tablespace [, tablespace ]...
| DATAFILE {filename | filenumber} [, filename | filenumber]...}
UNTIL [CONSISTENT WITH] CONTROLFILE }
where the parallel clause has the following syntax:
{ NOPARALLEL | PARALLEL [ integer ] }
where the managed clause has the following syntax:
MANAGED STANDBY DATABASE recover_clause | cancel_clause | finish_clause
where the recover_clause has the following syntax:
{ { DISCONNECT [ FROM SESSION ] | { TIMEOUT integer | NOTIMEOUT } }
| { NODELAY | DEFAULT DELAY | DELAY integer } | NEXT integer
| { EXPIRE integer | NO EXPIRE } | parallel_clause
| USING CURRENT LOGFILE | UNTIL CHANGE integer
| THROUGH { [ THREAD integer ] SEQUENCE integer
| ALL ARCHIVELOG | { ALL | LAST | NEXT } SWITCHOVER} }
[ DISCONNECT [ FROM SESSION ] | { TIMEOUT integer | NOTIMEOUT }
| { NODELAY | DEFAULT DELAY | DELAY integer } | NEXT integer
| { EXPIRE integer | NO EXPIRE } | parallel_clause
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
STANDBY DATABASE
Recovers the standby database using the control file and archived redo log files
copied from the primary database. The standby database must be mounted but not
open.
DATABASE
Recovers the entire database.
UNTIL CANCEL
Specifies an incomplete, cancel-based recovery. Recovery proceeds by prompting
you with suggested filenames of archived redo log files, and recovery completes
when you specify CANCEL instead of a filename.
UNTIL TIME
Specifies an incomplete, time-based recovery. Use single quotes, and the following
format:
'YYYY-MM-DD:HH24:MI:SS'
UNTIL CHANGE
Specifies an incomplete, change-based recovery. integer is the number of the System
Change Number (SCN) following the last change you wish to recover. For example,
if you want to restore your database up to the transaction with an SCN of 9, you
would specify UNTIL CHANGE 10.
USING BACKUP CONTROLFILE
Specifies that a backup of the control file be used instead of the current control file.
TABLESPACE
Recovers a particular tablespace. tablespace is the name of a tablespace in the current
database. You may recover up to 16 tablespaces in one statement.
DATAFILE
Recovers a particular datafile. You can specify any number of datafiles.
STANDBY TABLESPACE
Reconstructs a lost or damaged tablespace in the standby database using archived
redo log files copied from the primary database and a control file.
STANDBY DATAFILE
Reconstructs a lost or damaged datafile in the standby database using archived redo
log files copied from the primary database and a control file.
UNTIL CONSISTENT WITH CONTROLFILE
Specifies that the recovery of an old standby datafile or tablespace uses the current
standby database control file.
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 Quick Start 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 serial recovery processing. This is the default.
MANAGED STANDBY DATABASE
Specifies sustained standby recovery mode. This mode assumes that the standby
database is an active component of an overall standby database architecture. A
primary database actively archives its redo log files to the standby site. As these
archived redo logs arrive at the standby site, they become available for use by a
managed standby recovery operation. Sustained standby recovery is restricted to
media recovery.
For more information on the parameters of this clause, see the Oracle Database
Backup and Recovery Advanced 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
Applies a delayed archivelog immediately to the standby database overriding any
DELAY setting in the LOG_ARCHIVE_DEST_n parameter on the primary database.
If you omit this clause, application of the archivelog is delayed according to the
parameter setting. If DELAY was not specified in the parameter, the archivelog is
applied immediately.
DEFAULT DELAY
Waits the default number of minutes specified in the LOG_ARCHIVE_DEST_n
initialization parameter before applying the archived redo logs.
DELAY integer
Waits integer minutes before applying the archived redo logs.
NEXT integer
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
Disables a previously specified EXPIRE integer option.
USING CURRENT LOGFILE
Recovers redo from standby online logs as they are being filled, without requiring
them to be archived in the standby database first.
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 and
open, and the tablespace must be offline.
To perform media recovery on a datafile, the database can remain open and
mounted with the damaged datafiles offline (unless the file is part of the SYSTEM
tablespace).
Before using the RECOVER command you must have restored copies of the
damaged 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
REMARK
Syntax
REM[ARK]
Begins a comment in a script. SQL*Plus does not interpret the comment as a
command.
Usage
The REMARK command must appear at the beginning of a line, and the comment
ends at the end of the line. A line cannot contain both a comment and a command.
A "–" at the end of a REMARK line is treated as a line continuation character.
For details on entering comments in scripts using the SQL comment delimiters, /* ...
*/, or the ANSI/ISO comment delimiter, - -, see "Placing Comments in Scripts" on
page 6-9.
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;
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 on page 13-97 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.
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.
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
The report header or footer text. Enter text in single quotes if you want to place
more than one word on a single line. The default is NULL.
variable
A substitution variable or any of the following system-maintained values.
SQL.LNO is the current line number, SQL.PNO is the current page number,
SQL.CODE is the current error code, SQL.RELEASE is the current Oracle Database
release number, and SQL.USER is the current username.
To print one of these values, reference the appropriate variable in the report header
or footer. You can use the FORMAT clause to format variable.
OFF
Turns the report header or footer off (suppresses its display) without affecting its
definition.
COL n
Indents to column n of the current line (backward if column n has been passed).
Column in this context means print position, not table column.
S[KIP] [n]
Skips to the start of a new line n times; if you omit n, one time; if you enter zero for
n, backward to the start of the current line.
TAB n
Skips forward n columns (backward if you enter a negative value for n). Column in
this context means print position, not table column.
LE[FT] CE[NTER] R[IGHT]
Left-align, center, and right-align data on the current line respectively. SQL*Plus
aligns following data items as a group, up to the end of the printspec or the next
LEFT, CENTER, RIGHT, or COL command. CENTER and RIGHT use the SET
LINESIZE value to calculate the position of the data item that follows.
BOLD
Prints data in bold print. SQL*Plus represents bold print on your terminal by
repeating the data on three consecutive lines. On some operating systems, SQL*Plus
may instruct your printer to print bold text on three consecutive lines, instead of
bold.
FORMAT text
Specifies a format model that determines the format of data items up to the next
FORMAT clause or the end of the command. The format model must be a text
constant such as A10 or $999. See COLUMN on page 13-31 for more information on
formatting and valid format models.
If the datatype of the format model does not match the datatype of a given data
item, the FORMAT clause has no effect on that item.
If no appropriate FORMAT model precedes a given data item, SQL*Plus prints
NUMBER values according to the format specified by SET NUMFORMAT or, if you
have not used SET NUMFORMAT, the default format. SQL*Plus prints DATE
values using the default format.
Usage
If you do not enter a printspec clause before the text or variables, REPHEADER left
justifies the text or variables.
You can use any number of constants and variables in a printspec. SQL*Plus
displays the constants and variables in the order you specify, positioning and
formatting each constant or variable as specified by the printspec clauses that
precede it.
Examples
To define "EMPLOYEE LISTING REPORT" as a report header on a separate page,
and to center it, enter:
REPHEADER PAGE CENTER 'EMPLOYEE LISTING REPORT'
TTITLE RIGHT 'Page: ' FORMAT 999 SQL.PNO
SELECT LAST_NAME, SALARY
FROM EMP_DETAILS_VIEW
WHERE SALARY > 12000;
Page: 1
EMPLOYEE LISTING REPORT
Page: 2
LAST_NAME SALARY
------------------------- ----------
King 24000
Kochhar 17000
De Haan 17000
Russell 14000
Partners 13500
Hartstein 13000
----------
sum 98500
6 rows selected.
RUN
Syntax
R[UN]
Lists and executes the SQL command or PL/SQL block currently stored in the SQL
buffer.
The buffer has no command history list and does not record SQL*Plus commands.
Usage
RUN causes the last line of the SQL buffer to become the current line.
The slash command (/) functions similarly to RUN, but does not list the command
in the SQL buffer on your screen. The SQL buffer always contains the last SQL
statement or PL/SQL block entered.
Examples
Assume the SQL buffer contains the following script:
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.
SAVE
Syntax
SAV[E] [FILE] file_name[.ext] [CRE[ATE] | REP[LACE] | APP[END]]
Saves the contents of the SQL buffer in an operating system script. In iSQL*Plus,
click the Save Script button to save the Input area contents to a script.
The buffer has no command history list and does not record SQL*Plus commands.
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]
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} on page 13-133 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
SET
Sets a system variable to alter the SQL*Plus environment settings for your current
session, for example, to:
Q customize HTML formatting
Q enable or disable the printing of column headings
Q set the number of lines per page
Q set the display width for data
You also use the Preferences screens in iSQL*Plus to set system variables.
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.
SET ROLE and SET TRANSACTION are SQL commands (see the Oracle Database
SQL Reference for more information). When not followed by the keywords
TRANSACTION or ROLE, SET is assumed to be a SQL*Plus command.
SET APPINFO{ON | OFF | text} on Sets automatic registering of scripts through the
page 13-107 DBMS_APPLICATION_INFO package.
SET ARRAYSIZE {15 | n} on Sets the number of rows, called a batch, that SQL*Plus will
page 13-109 fetch from the database at one time.
SET AUTOCOMMIT{ON | OFF | IMMEDIATE | n} on Controls when Oracle Database commits pending changes
page 13-109 to the database.
SET AUTOPRINT {ON | OFF} on Sets the automatic printing of bind variables.
page 13-109
SET AUTORECOVERY [ON | OFF] on ON sets the RECOVER command to automatically apply
page 13-110 the default filenames of archived redo log files needed
during recovery.
SET AUTOTRACE {ON | OFF | TRACE[ONLY]} on Displays a report on the execution of successful SQL DML
page 13-110 statements (SELECT, INSERT, UPDATE or DELETE).
[EXPLAIN] [STATISTICS]
SET BLOCKTERMINATOR {. | c | ON | OFF} on Sets the non-alphanumeric character used to end PL/SQL
page 13-111 blocks to c.
SET COMPATIBILITY{V7 | V8 | NATIVE} on Specifies the version of Oracle Database to which you are
page 13-113 currently connected.
SET CONCAT [. | c | ON | OFF} on Sets the character you can use to terminate a substitution
page 13-114 variable reference if you wish to immediately follow the
variable with a character that SQL*Plus would otherwise
interpret as a part of the substitution variable name.
SET COPYCOMMIT {0 | n} on Controls the number of batches after which the COPY
page 13-114 command commits changes to the database.
SET COPYTYPECHECK {ON | OFF} on Sets the suppression of the comparison of datatypes while
page 13-114 inserting or appending to tables with the COPY command.
SET DEFINE {& | c | ON | OFF} on Sets the character used to prefix variables to c.
page 13-114
SET DESCRIBE [DEPTH {1 | n | ALL}] [LINENUM on Sets the depth of the level to which you can recursively
page 13-115 describe an object.
{ON | OFF}] [INDENT {ON | OFF}]
SET ECHO {ON | OFF} on Controls whether the START command lists each
page 13-116 command in a script as the command is executed.
*SET EDITFILE file_name [ .ext] on Sets the default filename for the EDIT command.
page 13-116
SET EMBEDDED {ON | OFF} on Controls where on a page each report begins.
page 13-116
SET ESCAPE {\ | c | ON | OFF} on Defines the character you enter as the escape character.
page 13-117
SET FEEDBACK {6 | n | ON | OFF} on Displays the number of records returned by a query when
page 13-117 a query selects at least n records.
SET FLAGGER {OFF | ENTRY on Checks to make sure that SQL statements conform to the
page 13-118 ANSI/ISO SQL92 standard.
| INTERMEDIATE | FULL}
*SET FLUSH {ON | OFF} on Controls when output is sent to the user's display device.
page 13-118
SET HEADSEP { | | c | ON | OFF} on Defines the character you enter as the heading separator
page 13-119 character.
SET INSTANCE [instance_path | LOCAL] on Changes the default instance for your session to the
page 13-119 specified instance path.
SET LINESIZE {80 | n} on Sets the total number of characters that SQL*Plus displays
page 13-120 on one line before beginning a new line.
SET LINESIZE {150 | n} in iSQL*Plus
SET LOBOFFSET {n | 1} on Sets the starting position from which CLOB and NCLOB
page 13-120 data is retrieved and displayed.
SET LOGSOURCE [pathname] on Specifies the location from which archive logs are retrieved
page 13-121 during recovery.
SET LONG {80 | n} on Sets maximum width (in bytes) for displaying LONG,
page 13-121 CLOB, NCLOB and XMLType values; and for copying
LONG values.
SET LONGCHUNKSIZE {80 | n} on Sets the size (in bytes) of the increments in which SQL*Plus
page 13-121 retrieves a LONG, CLOB, NCLOB or XMLType value.
SET MARKUP HTML [ON | OFF] [HEAD text] on Outputs HTML marked up text, which is the output used
page 13-122 by iSQL*Plus.
[BODY text] [TABLE text] [ENTMAP {ON | OFF}]
[SPOOL {ON | OFF}] [PREFORMAT {ON | OFF}]
SET NEWPAGE {1 | n | NONE} on Sets the number of blank lines to be printed from the top of
page 13-123 each page to the top title.
SET NULL text on Sets the text that represents a null value in the result of a
page 13-124 SQL SELECT command.
SET NUMFORMAT format on Sets the default format for displaying numbers.
page 13-124
SET NUMWIDTH {10 | n} on Sets the default width for displaying numbers.
page 13-124
SET PAUSE {ON | OFF | text} on Enables you to control scrolling of your terminal when
page 13-125 running reports.
SET RECSEP {WRAPPED | EACH | OFF} on RECSEP tells SQL*Plus where to make the record
page 13-125 separation.
SET SERVEROUTPUT {ON | OFF} [SIZE n] on Controls whether to display the output (that is,
page 13-126 DBMS_OUTPUT PUT_LINE) of stored procedures or
[FORMAT {WRAPPED | WORD_WRAPPED PL/SQL blocks in SQL*Plus.
| TRUNCATED}]
*SET SHIFTINOUT {VISIBLE | INVISIBLE} on Enables correct alignment for terminals that display shift
page 13-128 characters.
*SET SHOWMODE {ON | OFF} on Controls whether SQL*Plus lists the old and new settings
page 13-128 of a SQL*Plus system variable when you change the setting
with SET.
*SET SQLBLANKLINES {ON | OFF} on Controls whether SQL*Plus puts blank lines within a SQL
page 13-129 command or script.
SET SQLCASE {MIXED | LOWER | UPPER} on Converts the case of SQL commands and PL/SQL blocks
page 13-129 just prior to execution.
*SET SQLCONTINUE {> | text} on Sets the character sequence SQL*Plus displays as a prompt
page 13-130 after you continue a SQL*Plus command on an additional
line using a hyphen (–).
*SET SQLNUMBER {ON | OFF} on Sets the prompt for the second and subsequent lines of a
page 13-130 SQL command or PL/SQL block.
SET SQLPLUSCOMPATIBILITY {x.y[.z]} on Sets the behavior or output format of VARIABLE to that of
page 13-130 the release or version specified by x y [z].
SET SQLTERMINATOR {; | c | ON | OFF} on Sets the character used to end and execute SQL commands
page 13-133 to c.
*SET SUFFIX {SQL | text} on Sets the default file that SQL*Plus uses in commands that
page 13-133 refer to scripts.
*SET TAB {ON | OFF} on Determines how SQL*Plus formats white space in terminal
page 13-134 output.
*SET TERMOUT {ON | OFF} on Controls the display of output generated by commands
page 13-134 executed from a script.
*SET TIME {ON | OFF} on Controls the display of the current time.
page 13-134
*SET TRIMOUT {ON | OFF} on Determines whether SQL*Plus puts trailing blanks at the
page 13-135 end of each displayed line.
*SET TRIMSPOOL {ON | OFF} on Determines whether SQL*Plus puts trailing blanks at the
page 13-135 end of each spooled line.
SET UNDERLINE {- | c | ON | OFF} on Sets the character used to underline column headings in
page 13-135 SQL*Plus reports to c.
SET VERIFY {ON | OFF} on Controls whether SQL*Plus lists the text of a SQL
page 13-135 statement or PL/SQL command before and after SQL*Plus
replaces substitution variables with values.
SET WRAP {ON | OFF} on Controls whether SQL*Plus truncates the display of a
page 13-135 SELECTed row if it is too long for the current line width.
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
Example
To set the recovery mode to AUTOMATIC, enter
SET AUTORECOVERY ON
RECOVER DATABASE
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
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 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;
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
SET COPYC[OMMIT] {0 | n}
Controls the number of rows after which the COPY command commits changes to
the database.
COPY commits rows to the destination database each time it copies n row batches.
Valid values are zero to 5000. You can set the size of a batch with the ARRAYSIZE
variable. If you set COPYCOMMIT to zero, COPY performs a commit only at the
end of a copy operation.
SET DESCRIBE [DEPTH {1 | n | ALL}] [LINENUM {ON | OFF}] [INDENT {ON | OFF}]
Sets the depth of the level to which you can recursively describe an object.
The valid range of the DEPTH clause is from 1 to 50. If you SET DESCRIBE DEPTH
ALL, then the depth will be set to 50, which is the maximum level allowed. You can
also display the line number and indentation of the attribute or column name when
an object contains multiple object types. Use the SET LINESIZE command to control
the width of the data displayed.
See DESCRIBE on page 13-59 for more information about describing objects.
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
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
Example
If you define the escape character as an exclamation point (!), then
SET ESCAPE !
ACCEPT v1 PROMPT 'Enter !&1:'
Enter &1:
To set the escape character back to the default value of \ (backslash), enter
SET ESCAPE ON
Example
To suppress the display of column headings in a report, enter
SET HEADING OFF
Higgins 12000
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.
SET LOBOF[FSET] {1 | n}
Sets the starting position from which CLOB and NCLOB data is retrieved and
displayed.
Example
To set the starting position from which a CLOB column's data is retrieved to the
22nd position, enter
SET LOBOFFSET 22
The CLOB data will wrap on your screen; SQL*Plus will not truncate until the 23rd
character.
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
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.
SET MARK[UP] HTML [ON | OFF] [HEAD text] [BODY text] [TABLE text] [ENTMAP
{ON | OFF}] [SPOOL {ON | OFF}] [PRE[FORMAT] {ON | OFF}]
Outputs HTML marked up text, which is the output used by iSQL*Plus.
Beware of using options which generate invalid HTML output in iSQL*Plus as it
may corrupt the browser screen. The HEAD and BODY options may be useful for
dynamic reports and for reports saved to local files.
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.
See "MARKUP Options" on page 4-19 for detailed information. For examples of
usage, see SET MARK[UP] HTML [ON | OFF] [HEAD text] [BODY text] [TABLE
text] [ENTMAP {ON | OFF}] [SPOOL {ON | OFF}] [PRE[FORMAT] {ON | OFF}]
on page 13-122, and Chapter 8, "Generating HTML Reports from SQL*Plus" on
page 8-1.
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:
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:
first page) and clears the screen on most terminals. If you set NEWPAGE to NONE,
SQL*Plus does not print a blank line or formfeed between the report pages.
to use the default field width and formatting model specified by SET NUMWIDTH.
SET RECSEPCHAR { | c}
Defines the character to display or print to separate records.
A record separator consists of a single line of the RECSEPCHAR (record separating
character) repeated LINESIZE times. The default is a single space.
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:
Trigger Created.
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
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
D
-
X
Example
To set the SQL*Plus command continuation prompt to an exclamation point
followed by a space, enter
SET SQLCONTINUE '! '
SET SQLPRE[FIX] {# | c}
SET SQLPREFIX is not supported in iSQL*Plus
Sets the SQL*Plus prefix character. While you are entering a SQL command or
PL/SQL block, you can enter a SQL*Plus command on a separate line, prefixed by
the SQL*Plus prefix character. SQL*Plus will execute the command immediately
without affecting the SQL command or PL/SQL block that you are entering. The
prefix character must be a non-alphanumeric character.
Example
You need the Select Any Table privilege to successfully run the following example
scripts.
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
SET SQLPROMPT "_USER > "
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 change the default command-file extension from the default, .SQL to .TXT, enter
SET SUFFIX TXT
SHOW
Syntax
SHO[W] option
where option represents one of the following terms or clauses:
system_variable
ALL
BTI[TLE]
ERR[ORS] [ { FUNCTION | PROCEDURE | PACKAGE | PACKAGE BODY | TRIGGER
| VIEW | TYPE | TYPE BODY | DIMENSION | JAVA CLASS } [schema.]name]
LNO
PARAMETERS [parameter_name]
PNO
RECYC[LEBIN] [original_name]
REL[EASE]
REPF[OOTER]
REPH[EADER]
SGA
SPOO[L] (Not available in iSQL*Plus)
SQLCODE
TTI[TLE]
USER
Shows the value of a SQL*Plus system variable or the current SQL*Plus
environment. SHOW SGA requires a DBA privileged login.
Terms
system_variable
Represents any system variable set by the SET command.
ALL
Lists the settings of all SHOW options, except ERRORS and SGA, in alphabetical
order.
BTI[TLE]
Shows the current BTITLE definition.
ERR[ORS] [{FUNCTION | PROCEDURE | PACKAGE | PACKAGE BODY | TRIGGER
| VIEW | TYPE | TYPE BODY | DIMENSION | JAVA CLASS} [schema.]name]
The SHOW PARAMETERS command, without any string following the command,
displays all initialization parameters.
The column names and formats used in the SHOW PARAMETERS output is set in
the site profile file, glogin.sql. The value column display may be truncated.
Your output may vary depending on the version and configuration of the Oracle
Database server to which you are connected. You need SELECT ON
PNO
Shows the current page number.
RECYC[LEBIN] [original_name]
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
The output columns can be formatted with the COLUMN command. The default
COLUMN formatting is in the site profile, glogin.sql.
For DBAs, the command lists their own objects as they have their own
user_recyclebin view.
REL[EASE]
Shows the release number of Oracle Database that SQL*Plus is accessing.
REPF[OOTER]
Shows the current REPFOOTER definition.
REPH[EADER]
Shows the current REPHEADER definition.
SPOO[L]
Shows whether output is being spooled.
SGA
Displays information about the current instance's System Global Area. You need
SELECT ON V_$SGA object privileges otherwise you will receive a message
ORA-00942: table or view does not exist
SQLCODE
Shows the value of SQL.SQLCODE (the SQL return code of the most recent
operation).
TTI[TLE]
Shows the current TTITLE definition.
USER
Shows the username you are currently using to access SQL*Plus. If you connect as
"/ AS SYSDBA", then the SHOW USER command displays
USER is "SYS"
Examples
To display information about the SGA, enter
SHOW SGA
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
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
SHUTDOWN
Syntax
SHUTDOWN [ABORT | IMMEDIATE | NORMAL | TRANSACTIONAL [LOCAL]]
Shuts down a currently running Oracle Database instance, optionally closing and
dismounting a database.
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]
Performs a planned shutdown of an instance while allowing active transactions to
complete first. It prevents clients from losing work without requiring all users to log
off.
No client can start a new transaction on this instance. Attempting to start a new
transaction results in disconnection. After completion of all transactions, any client
still connected to the instance is disconnected. Now the instance shuts down just as
it would if a SHUTDOWN IMMEDIATE statement was submitted. The next startup
of the database will not require any instance recovery procedures.
The LOCAL mode specifies a transactional shutdown on the local instance only, so
that it only waits on local transactions to complete, not all transactions. This is
useful, for example, for scheduled outage maintenance.
Usage
SHUTDOWN with no arguments is equivalent to SHUTDOWN NORMAL.
You must be connected to a database as SYSOPER, or SYSDBA. You cannot connect
through a multi-threaded server. See CONNECT on page 13-48 for more
information about connecting to a database.
Examples
To shutdown the database in normal mode, enter
SHUTDOWN
Database closed.
Database dismounted.
Oracle instance shut down.
SPOOL
Syntax
SPO[OL] [file_name[.ext] [CRE[ATE] | REP[LACE] | APP[END]] | OFF | OUT]
Stores query results in a file, or optionally sends the file to a printer. In iSQL*Plus,
use the preference settings to direct output to a file.
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).
CRE[ATE]
Creates a new file with the name specified.
REP[LACE]
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
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.
Use SET SQLPLUSCOMPAT[IBILITY] 9.2 or earlier to use the earlier behavior.
However, this will also disable other functionality that is available in SQL*Plus
Release 10.1. See "SQL*Plus Compatibility Matrix" on page 13-131 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
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. Only the url form is supported in
iSQL*Plus. You can pass values to script variables in the usual way.
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]
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} on page 13-133 for
information on changing this 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.
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) on page 13-6 and @@ (double "at" sign) on
page 13-8 for further information on these commands. See "Disabling SQL*Plus,
SQL, and PL/SQL Commands" on page 10-4 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, SALARY
FROM EMP_DETAILS_VIEW
WHERE JOB_ID='&1' AND SALARY>&2;
STARTUP
Syntax
STARTUP options | upgrade_options
where options has the following syntax:
[FORCE] [RESTRICT] [PFILE= filename] [QUIET] [ MOUNT [dbname] |
[ OPEN [open_options] [dbname ] ] | NOMOUNT ]
where open_options has the following syntax:
READ {ONLY | WRITE [RECOVER]} | RECOVER
and where upgrade_options has the following syntax:
[PFILE=filename] {UPGRADE | DOWNGRADE} [QUIET]
Starts an Oracle Database instance with several options, including mounting and
opening a 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
Causes the specified parameter file to be used while starting up the instance. If
PFILE is not specified, then the default STARTUP parameter file is used. The
default file used is platform specific. For example, the default file is
$ORACLE_HOME/dbs/init$ORACLE_SID.ora on UNIX, and
%ORACLE_HOME%\database\initORCL.ora on Windows.
QUIET
Suppresses the display of System Global Area information for the starting instance.
MOUNT dbname
Mounts a database but does not open it.
dbname is the name of the database to mount or open. If no database name is
specified, the database name is taken from the initialization parameter DB_NAME.
OPEN
Mounts and opens the specified database.
NOMOUNT
Causes the database not to be mounted upon instance startup.
Cannot be used with MOUNT, or OPEN.
RECOVER
Specifies that media recovery should be performed, if necessary, before starting the
instance. STARTUP RECOVER has the same effect as issuing the RECOVER
DATABASE command and starting an instance. Only complete recovery is possible
with the RECOVER option.
Recovery proceeds, if necessary, as if AUTORECOVERY is set to ON, regardless of
whether or not AUTORECOVERY is enabled. If a redo log file is not found in the
expected location, recovery continues as if AUTORECOVERY is disabled, by
prompting you with the suggested location and name of the subsequent log files
that need to be applied.
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.
See the Oracle Database Upgrade Guide for details about preparing for, testing and
implementing a database version upgrade.
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.
See the Oracle Database Upgrade Guide for details about preparing for, testing and
implementing a database version downgrade.
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.
Usage
You must be connected to a database as SYSOPER, or SYSDBA. You cannot be
connected through a multi-threaded server.
STARTUP with no arguments is equivalent to STARTUP OPEN.
STARTUP OPEN RECOVER mounts and opens the database even when recovery
fails.
Examples
To start an instance using the standard parameter file, mount the default database,
and open the database, enter
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
STORE
Syntax
STORE SET file_name[.ext] [ CRE[ATE | REP[LACE] | APP[END]]
Saves attributes of the current SQL*Plus environment in a script.
Terms
See SAVE on page 13-101 for information on the other terms and clauses in the
STORE command syntax.
SET
Saves the values of the system variables.
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
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.
STOP
Lists the current timer's name and timing data, then deletes the timer. If any other
timers are active, the next most recently STARTed timer becomes the current timer.
Enter TIMING with no clauses to list the number of active timers. For other
information about TIMING, see SET AUTOTRACE
Usage
You can use this data to do a performance analysis on any commands or blocks run
during the period.
Refer to the SET TIMING command for information on automatically displaying
timing data after each SQL command or PL/SQL block you run.
To delete all timers, use the CLEAR TIMING command.
Examples
To create a timer named SQL_TIMER, enter
TIMING START SQL_TIMER
To list the current timer's title and accumulated time and to remove the timer, enter
TIMING STOP
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) on page C-5 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
A substitution variable or any of the following system-maintained values,
SQL.LNO (the current line number), SQL.PNO (the current page number),
SQL.RELEASE (the current Oracle Database release number), SQL.SQLCODE (the
current error code), or SQL.USER (the current username).
To print one of these values, reference the appropriate variable in the title. You can
format variable with the FORMAT clause.
SQL*Plus substitution variables (& variables) are expanded before TTITLE is
executed. The resulting string is stored as the TTITLE text. During subsequent
execution for each page of results, the expanded value of a variable may itself be
interpreted as a substitution variable with unexpected results.
You can avoid this double substitution in a TTITLE 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 TTITLE, enclose it in
quotes so that it is only substituted once.
OFF
Turns the title off (suppresses its display) without affecting its definition.
ON
Turns the title on (restores its display). When you define a top title, SQL*Plus
automatically sets TTITLE to ON.
COL n
Indents to column n of the current line (backward if column n has been passed).
Here "column" means print position, not table column.
S[KIP] [n]
Skips to the start of a new line n times; if you omit n, one time; if you enter zero for
n, backward to the start of the current line.
TAB n
Skips forward n columns (backward if you enter a negative value for n). "Column"
in this context means print position, not table column.
LE[FT] | CE[NTER] | R[IGHT]
Left-align, center, and right-align data on the current line respectively. SQL*Plus
aligns following data items as a group, up to the end of the printspec or the next
LEFT, CENTER, RIGHT, or COL command. CENTER and RIGHT use the SET
LINESIZE value to calculate the position of the data item that follows.
BOLD
Prints data in bold print. SQL*Plus represents bold print on your terminal by
repeating the data on three consecutive lines. On some operating systems, SQL*Plus
may instruct your printer to print bold text on three consecutive lines, instead of
bold.
FORMAT text
Specifies a format model that determines the format of following data items, up to
the next FORMAT clause or the end of the command. The format model must be a
text constant such as A10 or $999. See the COLUMN command on page 13-31 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.
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 on page 13-31 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
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
VARIABLE
Syntax
VAR[IABLE] [variable [NUMBER | CHAR | CHAR (n [CHAR | BYTE]) | NCHAR | NCHAR (n)
| VARCHAR2 (n [CHAR | BYTE]) | NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR
| BINARY_FLOAT | BINARY_DOUBLE] ]
Declares a bind variable that can be referenced in PL/SQL.
VARIABLE without arguments displays a list of all the variables declared in the
session. VARIABLE followed only by a variable name lists that variable.
See "Using Bind Variables" on page 6-32 for more information on bind variables. See
your PL/SQL User's Guide and Reference for more information about PL/SQL.
Terms
variable
Represents the name of the bind variable you wish to create.
NUMBER
Creates a variable of type NUMBER with fixed length.
CHAR
Creates a variable of type CHAR (character) with length one.
CHAR (n[CHAR | BYTE])
Creates a variable of type CHAR with length n bytes or n characters. The maximum
that n can be is 2000 bytes, and the minimum is 1 byte or 1 character. The maximum
n for a CHAR variable with character semantics is determined by the number of
bytes required to store each character for the chosen character set, with an upper
limit of 2000 bytes. The length semantics are determined by the length qualifiers
CHAR or BYTE, and if not explicitly stated, the value of the
NLS_LENGTH_SEMANTICS environment variable is applied to the bind variable.
Explicitly stating the length semantics at variable definition stage will always take
precedence over the NLS_LENGTH_SEMANTICS setting.
NCHAR
Creates a variable of type NCHAR (national character) with length one.
NCHAR (n)
Creates a variable of type NCHAR with length n characters. The maximum that n
can be is determined by the number of bytes required to store each character for the
chosen national character set, with an upper limit of 2000 bytes. The only exception
to this is when a SQL*Plus session is connected to a pre Oracle9i server, or the
SQLPLUSCOMPATIBILITY system variable is set to a version less than 9.0.0. In this
case the length n can be in bytes or characters depending on the chosen national
character set, with the upper limit of 2000 bytes still retained.
VARCHAR2 (n[CHAR | BYTE])
Creates a variable of type VARCHAR2 with length of up to n bytes or n characters.
The maximum that n can be is 4000 bytes, and the minimum is 1 byte or 1 character.
The maximum n for a VARCHAR2 variable with character semantics is determined
by the number of bytes required to store each character for the chosen character set,
with an upper limit of 4000 bytes. The length semantics are determined by the
length qualifiers CHAR or BYTE, and if not explicitly stated, the value of the
NLS_LENGTH_SEMANTICS environment variable is applied to the bind variable.
Explicitly stating the length semantics at variable definition stage will always take
precedence over the NLS_LENGTH_SEMANTICS setting.
NVARCHAR2 (n)
Creates a variable of type NVARCHAR2 with length of up to n characters. The
maximum that n can be is determined by the number of bytes required to store each
character for the chosen national character set, with an upper limit of 4000 bytes.
The only exception to this is when a SQL*Plus session is connected to a pre Oracle9i
server, or the SQLPLUSCOMPATIBILITY system variable is set to a version less
than 9.0.0. In this case the length n can be in bytes or characters depending on the
chosen national character set, with the upper limit of 4000 bytes still retained.
CLOB
Creates a variable of type CLOB.
NCLOB
Creates a variable of type NCLOB.
REFCURSOR
Creates a variable of type REF CURSOR.
BINARY_FLOAT
Creates a variable of type BINARY_FLOAT.
BINARY_DOUBLE
Creates a variable of type BINARY_DOUBLE.
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 on page 13-83 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}" on
page 13-109 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)
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;
/
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 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;
END;
/
------------
Total: $98,500.00
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.
For more information on creating CLOB columns, see your Oracle Database SQL
Reference
WHENEVER OSERROR
Syntax
WHENEVER OSERROR {EXIT [SUCCESS | FAILURE | n | variable | :BindVariable]
[COMMIT | ROLLBACK] | CONTINUE [COMMIT | ROLLBACK | NONE]}
Performs the specified action (exits SQL*Plus by default) if an operating system
error occurs (such as a file writing error).
In iSQL*Plus, performs the specified action (stops the current script by default) and
returns focus to the Workspace if an operating system error occurs.
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 on page 13-70 for
more information.
CONTINUE
Turns off the EXIT option.
COMMIT
Directs SQL*Plus to execute a COMMIT before exiting or continuing and save
pending changes to the database.
ROLLBACK
Directs SQL*Plus to execute a ROLLBACK before exiting or continuing and
abandon pending changes to the database.
NONE
Directs SQL*Plus to take no action before continuing.
Usage
If you do not enter the WHENEVER OSERROR command, the default behavior of
SQL*Plus is to continue and take no action when an operating system error occurs.
If you do not enter the WHENEVER SQLERROR command, the default behavior of
SQL*Plus is to continue and take no action when a SQL error occurs.
Examples
The commands in the following script cause iSQL*Plus to stop processing the
current script and return focus to the Input area on the Workspace:
cause SQL*Plus to exit and COMMIT any pending changes if a failure occurs when
reading from the output file:
WHENEVER OSERROR EXIT
START no_such_file
WHENEVER SQLERROR
Syntax
WHENEVER SQLERROR {EXIT [SUCCESS | FAILURE | WARNING | n | variable
| :BindVariable] [COMMIT | ROLLBACK] | CONTINUE [COMMIT | ROLLBACK | NONE]}
Performs the specified action (exits SQL*Plus by default) if a SQL command or
PL/SQL block generates an error.
In iSQL*Plus, performs the specified action (stops the current script by default) and
returns focus to the Workspace if a SQL command or PL/SQL block generates an
error.
Terms
[SUCCESS | FAILURE | WARNING | n | variable | :BindVariable]
Directs SQL*Plus to perform the specified action as soon as it detects a SQL
command or PL/SQL block error (but after printing the error message). SQL*Plus
will not exit on a SQL*Plus error.
EXIT [SUCCESS | FAILURE | WARNING | n | variable | :BindVariable]
Directs SQL*Plus to exit as soon as it detects a SQL command or PL/SQL block
error (but after printing the error message). SQL*Plus will not exit on a SQL*Plus
error. The EXIT clause of WHENEVER SQLERROR follows the same syntax as the
EXIT command. See EXIT on page 13-70 for more information.
CONTINUE
Turns off the EXIT option.
COMMIT
Directs SQL*Plus to execute a COMMIT before exiting or continuing and save
pending changes to the database.
ROLLBACK
Directs SQL*Plus to execute a ROLLBACK before exiting or continuing and
abandon pending changes to the database.
NONE
Directs SQL*Plus to take no action before continuing.
Usage
The WHENEVER SQLERROR command is triggered by SQL command or PL/SQL
block errors, and not by SQL*Plus command errors.
Examples
The commands in the following script cause iSQL*Plus to stop processing the
current script and return focus to the Input area on the Workspace:
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 SQL command error causes iSQL*Plus to stop processing the current
script and return focus to the Input area on the Workspace:
WHENEVER SQLERROR EXIT SQL.SQLCODE
select column_does_not_exiSt from dual;
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;
/
This appendix lists error messages with prefixes SP2- and CPY- generated by
SQL*Plus and iSQL*Plus:
Q SQL*Plus Error Messages
Q iSQL*Plus Error Messages
Q 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.
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.
Q Check that the destination is valid and that there is sufficient space on the
destination device.
Q Check the statement for a typing mistake in the directory name. Then issue
the statement again after correcting the directory name.
SP2-0110 Cannot create save file file_name
Cause: An attempt was made to save the content of the SQL buffer to a file and
the file could not be written. Possible causes:
Q An error was encountered when creating the destination file.
Q A directory name specified in the SAVE statement was not found.
Q Check that the destination is valid and that there is sufficient space on the
destination device.
Q Check the statement for a typing mistake in the directory name. Then issue
the statement again after correcting the directory name.
SP2-0111 Cannot close save file file_name
Cause: The file was in use.
Action: Release the file from the other process.
Q Make sure the file name specified is stored in the appropriate directory.
Q Make sure that the file has the privileges necessary for access. If it does not
then change privileges accordingly.
Q Consult operating system documentation or contact the System
Administrator.
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.
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.
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 PLUSTRACE role has been granted.
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.
SP2-0736 Command line overflow while substituting into line beginning string_
name
Cause: The maximum length of the command line was exceeded.
Action: Reduce the length of the data in the substitution variables used in the
command.
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.
SP2-0756 FROM clause length clause_len bytes exceeds maximum length max_
len
Cause: The FROM clause is too long.
Action: Reduce the string specified in the FROM clause.
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.
SP2-0858 Usage: SET MARKUP HTML [ON] [HEAD text] [BODY text] [TABLE
text] [PRE[FORMAT] {ON|OFF}]
Cause: An invalid option to SET MARKUP was entered in iSQL*Plus.
Action: Remove the invalid option.
SP2-0887 History size specified is non numeric or outside the range [0 -100]
Cause: The history size specified was either not a numeric value, or was not in
the range 0 to 100.
Action: Re-enter a numeric value in the range 0 to 100 for the history size.
SP2-0889 The value specified for the keyword type must be either URL or TEXT
Cause: The value entered for the specified keyword was invalid.
Action: Re-enter the command using a valid value for the specified keyword.
Valid values for the keyword "type" are "URL" or "TEXT".
SP2-0921 The value specified for the keyword action must be either EXECUTE or
LOAD
Cause: The value entered for the specified keyword was invalid.
Action: Re-enter the command using a valid value for the specified keyword.
Valid values for the keyword "action" are "EXECUTE" or "LOAD".
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
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.
The general SQL*Plus limits shown are valid for most operating systems.
Terms
Refer to 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
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
Specifies username[/password] @connect_identifier of the Oracle Database source or
destination database you wish to COPY FROM or COPY TO.
The COPY command does not support SYSDBA or SYSOPER privileged
connections. You must include a username. If you do not specify password in either
the COPY FROM clause or the COPY TO clause, SQL*Plus will prompt you for it.
SQL*Plus suppresses the display of your password response.
You must include the connect_identifier clause to specify the source or destination
database. The exact syntax depends on the Oracle Net communications protocol in
use. For more information, refer to the Oracle Net manual appropriate for your
protocol or contact your DBA.
APPEND
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.
USING query
Specifies a SQL query (SELECT command) determining which rows and columns
COPY copies.
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.
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/your_password@HQ TO JOHN/your_password@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/your_password@ORACLE01 -
CREATE SALESMEN (EMPLOYEE_ID, SA_MAN) -
USING SELECT EMPLOYEE_ID, LAST_NAME FROM EMPLOYEES -
WHERE JOB_ID='SA_MAN';
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
"Controlling Treatment of the Destination Table" on page B-6 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.
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/your_password@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 or in the
Input area of the iSQL*Plus Workspace rather than trying to enter them directly at
the command prompt.
Q If the destination table already exists, COPY reports an error and stops.
Q If the destination table does not already exist, COPY creates the table using the
copied data.
Use INSERT to insert data into an existing table. INSERT specifies the following
actions:
Q If the destination table already exists, COPY inserts the copied data in the
destination table.
Q If the destination table does not already exist, COPY reports an error and stops.
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:
Q If the destination table already exists, COPY inserts the copied data in the
destination table.
Q If the table does not already exist, COPY creates the table and then inserts the
copied data in it.
SQL*Plus then creates the table EMPLOYEE_COPY and copies the rows:
In this COPY command, the FROM clause directs COPY to connect you to the
database with the specification BOSTONDB as HR, with the password your_
password.
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.
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.
This appendix covers earlier versions of some SQL*Plus commands. While these
older commands still function within SQL*Plus, they are no longer supported. It is
recommended that you use the alternative SQL*Plus commands listed in the
following table.
COLUMN DEFAULT COLUMN CLEAR on Resets column display attributes to default values.
page 13-31
DOCUMENT REMARK on Places a comment which SQL*Plus does not
page 13-94 interpret as a command.
NEWPAGE SET NEWPAGE on Sets the number of blank lines to be printed from
page 13-123 the top of each page to the top title.
SET BUFFER EDIT on page 13-67 Enables the editing of the SQL*Plus command
buffer, or the contents of a saved file. Use the
SQL*Plus SAVE, GET, @ and START commands to
create and use external files.
SET SCAN SET DEFINE on Sets the character used to prefix substitution
page 13-114 variables.
SET SPACE SET COLSEP on Sets the text to be printed between SELECTed
page 13-112 columns.
TTITLE TTITLE on Places and formats a title at the top of each report
(old form) page 13-155 page or lists the current TTITLE definition.
DOC[UMENT] (obsolete)
Begins a block of documentation in a script.
For information on the current method of inserting comments in a script, see the
section "Placing Comments in Scripts" on page 6-9 and the REMARK command on
page 13-94.
After you type DOCUMENT and enter [Return], SQL*Plus displays the prompt
DOC> in place of SQL> until you end the documentation. The "pound" character (#)
on a line by itself ends the documentation.
If you have set DOCUMENT to OFF, SQL*Plus suppresses the display of the block
of documentation created by the DOCUMENT command. (See "SET DOC[UMENT]
{ON|OFF} (obsolete)" on page C-4.)
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 ESC[APE] {\ | c |
ON | OFF} on page 13-117 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 on page 13-155.
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'
Index-1
Numerics Product User Profile table, 10-12
starting, 4-11
0, number format, 7-5
starting the Windows service, 4-11
9, number format, 7-5 stopping, 4-13
test if running, 3-14
A ARCH background process, 13-15
ARCHIVE LOG
ABORT mode, 13-142
command, 11-4, 13-14
abort query, 5-12
mode, 11-4
ACCEPT command, 6-28, 13-11
argument
and DEFINE command, 13-51
in START command, 6-26
BINARY_DOUBLE clause, 13-11
ARRAYSIZE variable, 9-12, 13-104, 13-109
BINARY_FLOAT clause, 13-11
relationship to COPY command, B-4, B-8
customizing prompts for value, 6-29
ATTRIBUTE command, 13-17
DATE clause, 13-11
ALIAS clause, 13-17
DEFAULT clause, 13-12
and CLEAR COLUMN command, 13-18
FORMAT clause, 13-11
CLEAR clause, 13-17
HIDE clause, 13-12
clearing columns, 13-29, 13-32
NOPROMPT clause, 13-12
controlling display characteristics, 13-18
NUMBER clause, 6-30
display characteristics, 13-17
PROMPT clause, 6-28, 13-12
entering multiple, 13-18
access, denying and granting, 10-1
FORMAT clause, 13-18
AFIEDT.BUF
LIKE clause, 13-18
See editor
listing attribute display characteristics, 13-17
alias, 4-6
OFF clause, 13-18
ALIAS clause, 13-32
ON clause, 13-18
in ATTRIBUTE command, 13-17
restoring column display attributes, 13-18
ALL clause, 13-136
suppressing column display attributes, 13-18
ALTER command
AUDIT command
disabling, 10-5
disabling, 10-5
ampersands (&)
authentication
in parameters, 6-26, 13-6, 13-146
adding username/password entries, 10-11
substitution variables, 6-17
DBA access in iSQL*Plus, 10-11
ANALYZE command
AUTOCOMMIT variable, 5-14, 13-104, 13-109
disabling, 10-5
AUTOMATIC clause, 13-86
APPEND clause
AUTOPRINT variable, 13-104, 13-109
in COPY command, B-2, B-7
AUTORECOVERY variable, 13-104, 13-110
in SAVE command, 13-101, 13-144
autotrace report, 9-2
APPEND command, 6-3, 6-7, 13-13
AUTOTRACE variable, 9-2, 13-104, 13-110
APPINFO clause, 9-12, 13-107
Application Server, 10-11
authentication, 2-14 B
HTTP port, 4-12
background process
isqlplusctl utility, 4-11
startup after abnormal termination, 13-142
port in use, 3-12 batch mode, 13-71
Index-2
BEGIN command, 5-8 inserting space after every row, 7-15
disabling, 10-5 inserting space when break column
BINARY_DOUBLE clause changes, 7-14
ACCEPT command, 13-11 listing current break definition, 7-16, 13-22
VARIABLE command, 13-162 ON column clause, 7-13, 13-19
BINARY_FLOAT clause ON expr clause, 13-20
ACCEPT command, 13-11 ON REPORT clause, 7-21, 13-21
VARIABLE command, 13-161 ON ROW clause, 7-15, 13-21
bind variables, 6-32 printing "grand" and "sub" summaries, 7-21
creating, 13-160 printing summary lines at ends of reports, 7-21
displaying, 13-83 removing definition, 13-29
displaying automatically, 13-109, 13-162 SKIP clause, 7-15, 13-21
in PL/SQL blocks, 13-162 SKIP PAGE clause, 7-14, 7-15, 13-21
in SQL statements, 13-162 specifying multiple break columns, 7-15, 13-19
in the COPY command, 13-162 suppressing duplicate values, 7-13
blank line used in conjunction with COMPUTE, 7-17
in PL/SQL blocks, 5-8 used in conjunction with SET COLSEP, 13-112
in SQL commands, 5-7 used to format a REFCURSOR variable, 13-163
preserving in SQL commands, 13-106, 13-129 used with COMPUTE, 13-19, 13-21, 13-44
blocks, PL/SQL break definition
continuing, 5-8 listing current, 7-16, 13-22
editing in buffer, 6-3 removing current, 7-16, 13-29
editing with system editor, 6-2, 13-67 BREAKS clause, 7-16, 13-29
entering and executing, 5-8 browser, web, 8-2
listing current in buffer, 6-4 BTITLE clause, 13-136
saving current, 13-101 BTITLE command, 7-24, 13-24
setting character used to end, 13-104, 13-111 aligning title elements, 13-156
stored in SQL buffer, 5-8 BOLD clause, 13-157
timing statistics, 13-134 CENTER clause, 13-156
within SQL commands, 5-9 COL clause, 13-156
BLOCKTERMINATOR, 13-104, 13-111, 13-129, FORMAT clause, 13-157
13-133 indenting titles, 13-156
BODY clause, 4-20 LEFT clause, 13-156
BODY option, 4-20 OFF clause, 13-156
BOLD clause, 13-98, 13-157 old form, C-2
break columns, 7-12, 13-19 printing blank lines before bottom title, 7-27
inserting space when value changes, 7-14 referencing column value variable, 13-38
specifying multiple, 7-15 RIGHT clause, 13-156
suppressing duplicate values in, 7-13 SKIP clause, 13-156
BREAK command, 7-12, 13-19 suppressing current definition, 13-156
and SQL ORDER BY clause, 7-12, 7-13, 7-15, TAB clause, 13-156
13-20 TTITLE command, 13-24
clearing BREAKS, 7-16
displaying column values in titles, 7-31
DUPLICATES clause, 13-22
Index-3
buffer, 5-3 CHAR columns
appending text to a line in, 6-7, 13-13 changing format, 13-33
clearing your screen, 2-6 default format, 7-6
delete a single line, 6-4 definition from DESCRIBE, 13-59
delete the current line, 6-4 Character Map Windows utility
delete the last line, 6-4 choosing a font, 2-2, 2-10
deleting a range of lines, 6-4, 13-57 CLEAR clause, 7-9, 13-32
deleting a single line, 13-57 in ATTRIBUTE command, 13-17
deleting all lines, 6-3, 13-29, 13-57 CLEAR command, 13-29
deleting lines from, 6-9, 13-57 BREAKS clause, 7-16, 13-29
deleting the current line, 13-57 BUFFER clause, 6-3, 13-29
deleting the last line, 13-57 COLUMNS clause, 13-29
executing contents, 13-10, 13-100 COMPUTES clause, 13-29
inserting new line in, 6-8, 13-77 SCREEN clause, 6-31, 13-30
listing a range of lines, 6-4, 13-79 SQL clause, 13-30
listing a single line, 6-4, 13-79 TIMING clause, 13-30
listing all lines, 6-4, 13-79 clear screen button, 2-17
listing contents, 6-4, 13-79 clearing your screen, 2-6
listing the current line, 6-4, 13-79 client tier, 1-2
listing the last line, 6-4, 13-79 CLOB clause
loading into system editor, 13-67 VARIABLE command, 13-161
saving contents, 13-101 CLOB columns
screen area, 2-7 changing format, 13-33
SQL, 2-5 default format, 13-33
BUFFER clause, 6-3, 13-29 setting maximum width, 13-105, 13-121
BUFFER variable, C-3 setting retrieval position, 13-105, 13-120
buttons setting retrieval size, 9-13, 13-105, 13-121
cancel, 2-20, 4-3, 6-26 CLOSECURSOR variable, C-2, C-4
clear screen, 2-17 CMDSEP variable, 13-104, 13-111
execute, 2-17 COL clause, 7-28, 13-98, 13-156
load script, 2-17 colons (:)
log in, 2-13, 2-15 bind variables, 6-32
save script, 2-17 COLSEP variable, 13-104, 13-112
COLUMN command, 7-1, 13-31
ALIAS clause, 13-32
C and BREAK command, 13-21
cancel button, 2-20, 4-3, 6-26 and DEFINE command, 13-51
CANCEL clause, 13-87, 13-91 CLEAR clause, 7-9, 13-32
cancel query, 5-12 DEFAULT clause, C-2
cancelling an in-progress operation, 2-5 displaying column values in bottom titles, 7-32,
CENTER clause, 7-27, 13-98, 13-156 13-38
CHANGE command, 6-3, 6-5, 13-26 displaying column values in top titles, 7-31,
Change Password screen, 4-2 13-37
CHAR clause entering multiple, 13-39
VARIABLE command, 13-160 ENTMAP clause, 13-32
Index-4
FOLD_AFTER clause, 13-32, 13-33 copying values between tables, B-1, B-4, B-9
FOLD_BEFORE clause, 13-33 displaying values in bottom titles, 7-32, 13-38
FORMAT clause, 7-4, 7-6, 13-33 displaying values in top titles, 7-31, 13-37
formatting a REFCURSOR variable, 13-163 formatting CHAR, VARCHAR, LONG, and
formatting NUMBER columns, 7-4, 13-34 DATE, 13-33
HEADING clause, 7-2, 13-36 formatting in reports, 7-1, 13-31
HEADSEP character, 13-36 formatting MLSLABEL, RAW MLSLABEL,
JUSTIFY clause, 13-36 ROWLABEL, 13-33
LIKE clause, 7-9, 13-36 formatting NUMBER, 7-4, 13-34
listing column display attributes, 7-9, 13-31 listing display attributes for all, 7-9, 13-31
NEW_VALUE clause, 7-31, 13-37 listing display attributes for one, 7-9, 13-31
NEWLINE clause, 13-37 names in destination table when copying, B-3,
NOPRINT clause, 7-31, 9-12, 13-37 B-5
NULL clause, 13-37 printing line after values that overflow, 7-10,
OFF clause, 7-10, 13-38 13-106, 13-125
OLD_VALUE clause, 7-32, 13-38 resetting a column to default display, 7-9, 13-32,
ON clause, 7-10, 13-38 C-1
PRINT clause, 13-37 resetting all columns to default display, 13-29
resetting a column to default display, C-1 restoring display attributes, 7-10, 13-18, 13-38
resetting to default display, 7-9, 13-32, C-1 setting printing to off or on, 7-31, 9-12, 13-37
restoring column display attributes, 7-10, 13-38 starting new lines, 13-37
storing current date in variable for titles, 13-40 storing values in variables, 7-31, 13-37
suppressing column display attributes, 7-10, suppressing display attributes, 7-10, 13-18,
13-38 13-38
TRUNCATED clause, 7-7, 13-38 truncating display for all when value
WORD_WRAPPED clause, 7-7, 7-10, 13-38 overflows, 7-7, 13-135
WRAPPED clause, 7-7, 13-38 truncating display for one when value
column headings overflows, 7-7, 13-38
aligning, 13-36 wrapping display for all when value
changing, 7-1, 13-36 overflows, 7-7, 13-135
changing character used to underline, 13-107, wrapping display for one when value
13-135 overflows, 7-7, 13-38
changing to two or more words, 7-2, 13-36 wrapping whole words for one, 7-10
displaying on more than one line, 7-2, 13-36 COLUMNS clause, 13-29
suppressing printing in a report, 13-105, 13-118 comma, number format, 7-5
when truncated, 13-33 command files
when truncated for CHAR and LONG aborting and exiting with a return code, 6-15,
columns, 7-6 13-169, 13-171
when truncated for DATE columns, 7-6 creating with a system editor, 6-2
when truncated for NUMBER columns, 7-4 creating with SAVE, 13-101, 13-116
column separator, 13-104, 13-112, C-2 editing with system editor, 13-67
columns in @ ("at" sign) command, 6-14, 13-6
assigning aliases, 13-32 in EDIT command, 13-67
computing summary lines, 7-17, 13-42 in GET command, 13-72
copying display attributes, 7-9, 13-18, 13-36 in SAVE command, 6-3, 13-101
Index-5
command files (continued) ending, 5-7
in SQLPLUS command, 4-25, 6-14 entering and executing, 5-5
in START command, 6-13, 13-146 entering without executing, 5-7
including comments in, 6-9, 13-94 executing current, 13-10, 13-100
including more than one PL/SQL block, 6-2 following syntax, 5-6
including more than one SQL command, 6-2 listing current in buffer, 6-4
nesting, 6-15 saving current, 13-101
opening, 2-4 setting character used to end and run, 13-106
passing parameters to, 6-26, 13-6, 13-146 SQL*Plus
registering, 13-104, 13-107 command summary, 13-2
retrieving, 13-72 continuing on additional lines, 5-11, 13-1
running, 6-13, 13-6, 13-146 ending, 5-11, 13-1
running a series in sequence, 6-15 entering and executing, 5-10
running as you start SQL*Plus, 4-25, 6-14 entering during SQL command entry, 13-132
running in batch mode, 6-15, 13-71 obsolete command alternatives, C-1
saving, 2-4 stopping while running, 5-12
uniform resource locator, 13-6, 13-8, 13-146 tabs, 5-2
command keys, SQL*Plus Windows GUI, 2-4 types of, 5-2
command prompt variables that affect running, 5-12
SET SQLPROMPT, 9-13, 13-106, 13-132 comments
SQL*Plus, 4-8 including in command files, C-1
command-line including in scripts, 6-9, 13-94, C-1
configuring globalization support, 12-2 using -- to create, 6-10
installing help, 3-10 using /*...*/ to create, 6-10
command-line interface using REMARK, C-1
changing face and size, 2-2 using REMARK to create, 6-10, 13-94, C-1
Euro sign, 2-2 COMMIT clause, 13-70
special character, 2-2 WHENEVER OSERROR, 13-168
Windows Character Map utility, 2-2 WHENEVER SQLERROR, 13-170
commands COMMIT command, 5-13
collecting timing statistics on, 9-8, 13-153 communication between tiers, 1-2, 1-3
copying text, 2-3 COMPATIBILITY variable, 13-104, 13-113
disabled in schema, 14-20 compilation errors, 5-9, 13-137, 14-40
disabling, 10-4 COMPUTE command, 7-12, 13-42
echo on screen, 13-116 computing a summary on different
finding text, 2-6 columns, 7-22
host, running from SQL*Plus, 5-13, 13-75 LABEL clause, 7-18, 7-21, 13-43
listing current in buffer, 13-79 listing all definitions, 7-23, 13-43
pasting text, 2-6 maximum LABEL length, 13-43
re-enabling, 10-4 OF clause, 7-17
spaces, 5-2 ON, 13-43
SQL ON column clause, 7-17, 13-43
continuing on additional lines, 5-6 ON expr clause, 13-43
editing in buffer, 6-3 ON REPORT clause, 7-21, 13-43
editing with system editor, 13-67 printing "grand" and "sub" summaries, 7-21
Index-6
COMPUTE command (continued) continuing a long SQL*Plus command, 5-11, 13-1
printing multiple summaries on same cookies, configuring for iSQL*Plus, 3-25
column, 7-22 COPY command, 13-50, B-1, B-4
printing summary lines at ends of reports, 7-21 and @ ("at" sign), B-1, B-5
printing summary lines on a break, 7-17 and ARRAYSIZE variable, B-4, B-8
referencing a SELECT expression in OF, 13-43 and COPYCOMMIT variable, B-3, B-8
referencing a SELECT expression in ON, 13-43 and LONG variable, B-3, B-8
removing definitions, 7-24, 13-29 APPEND clause, B-2, B-7
used to format a REFCURSOR variable, 13-163 copying data between databases, B-4
COMPUTES clause, 13-29 copying data between tables on one
CONCAT variable, 6-23, 13-104, 13-114 database, B-9
configuration CREATE clause, B-2, B-6
globalization support creating a table, B-2, B-6
configuration parameter destination table, B-3, B-5
iSQLPlusAllowUserMarkup, 3-4 determining actions, B-5
iSQLPlusConnectIdList, 3-4 determining source rows and columns, B-3, B-6
log4j.rootLogger, 3-4 error messages, 14-54
configuring FROM clause, B-5
cookies for iSQL*Plus, 3-25 INSERT clause, B-3, B-7
javascript for iSQL*Plus, 3-25 inserting data in a table, B-3, B-7
Oracle Net, 3-12 interpreting messages, B-8
SQL*Plus, 3-1 mandatory connect identifier, B-2
Windows GUI, 3-26 naming the source table with SELECT, B-3, B-6
CONNECT command, 4-2, 13-48 query, B-3, B-6
and @ ("at" sign), 13-48 referring to another user’s table, B-9
changing password, 13-48, 13-49, 13-81 REPLACE clause, B-3, B-6
SYSDBA clause, 4-25, 13-49 replacing data in a table, B-3, B-6
SYSOPER clause, 4-25, 13-49 sample command, B-5, B-6
username/password, 13-48 service name, B-5, B-7, B-9
connect identifier, 13-48 specifying columns for destination, B-3, B-5
field, 2-12, 2-15 specifying the data to copy, B-3, B-6
in CONNECT command, 13-48 TO clause, B-5
in COPY command, B-1 username/password, B-2, B-5, B-7, B-9
in DESCRIBE command, 13-59 USING clause, B-3, B-6
in SQLPLUS command, 4-25 COPYCOMMIT variable, 13-104, 13-114
connect port conflict, 3-12 relationship to COPY command, B-3, B-8
connect string copying text, 2-3, 2-6
See connection identifier COPYTYPECHECK variable, 13-104, 13-114
connection identifier, 4-5, 4-10 CREATE clause
easy or abbreviated, 4-6 in COPY command, B-2, B-6
full, 4-6 CREATE command
net service name, 4-6 disabling, 10-5
CONTINUE clause entering PL/SQL, 5-9
WHENEVER OSERROR, 13-168 creating a PLAN_TABLE, 9-2
WHENEVER SQLERROR, 13-170 creating flat files, 7-35
Index-7
creating PLUSTRACE role, 9-3 DB2, 13-114
creating sample tables, 1-6 DBA, 11-1
creating the PRODUCT_USER_PROFILE connections, 3-17
table, 10-2 DBA Login screen, 2-13
cursor variables, 13-162 DBA Workspace, 2-17
iSQL*Plus access, 10-11
mode, 13-148
D privilege, 2-13, 13-148
database DBMS output, 9-13, 13-126
administrator, 11-1 DBMS_APPLICATION_INFO package, 9-12,
connect identifier, 13-48 13-104, 13-107
mounting, 13-149 DECLARE command
opening, 13-149 disabling, 10-5
database changes, saving automatically, 13-104, PL/SQL, 5-8
13-109 DEFAULT clause, 13-12
DATABASE clause, 13-88 default port conflict, 3-12
database files DEFINE command, 6-16, 13-51
recovering, 13-86 and system editor, 6-2, 13-54
database name at startup, 13-148 and UNDEFINE command, 6-16, 13-159
database schema, 9-2 CHAR values, 13-51
default, 13-49 SET DEFINE ON|OFF, 13-104, 13-114
DESCRIBE parameter, 13-59 substitution variables, 13-51
SHOW, 13-136 DEFINE variable
database tier, 1-2, 1-3 See substitution variable
databases DEL command, 6-3, 6-9, 13-57
connecting to default, 13-48 using an asterisk, 6-4, 13-57
connecting to remote, 13-48 DELETE command
copying data between, B-1, B-4 disabling, 10-5
copying data between tables on a single, B-9 DESCRIBE command (SQL*Plus), 5-4, 13-59
disconnecting without leaving SQL*Plus, 4-2, connect_identifier, 13-59
13-66 PL/SQL properties listed by, 13-60
mounting, 11-2 table properties listed by, 13-59
opening, 11-3 DISABLED keyword, disabling commands, 10-3
recovering, 11-5, 13-86 disabling
shutting down, 11-2, 11-3 iSQL*Plus, 3-24
starting, 11-2 PL/SQL commands, 10-5
DATAFILE clause, 13-88 SQL commands, 10-4
DATE SQL*Plus commands, 10-4
column definition from DESCRIBE, 13-59 DISCONNECT command, 4-2, 13-66
DATE clause, 13-11 DOCUMENT command, C-1, C-3
DATE columns REMARK as newer version of, C-3
changing format, 13-34, 13-40 DOCUMENT variable, C-2, C-4
default format, 7-6 DROP command, disabling, 10-5
date, storing current in variable for titles, 7-32, DUPLICATES clause, 13-22
13-37, 13-40 dynamic reports, creating, 8-8
Index-8
E compilation errors, 5-9, 13-137, 14-40
making line containing current, 6-5
ECHO
escape characters, definition of, 13-105, 13-117
SET command, 13-116 ESCAPE variable, 6-23, 13-105, 13-117
ECHO variable, 6-14, 13-105, 13-116 Euro sign
Ed on UNIX, 13-54
command-line interface, 2-2
EDIT command, 6-2, 13-53, 13-54, 13-67
GUI, 2-9, 2-10
creating scripts with, 6-2
example
defining _EDITOR, 13-67
interactive HTML report, 8-2, 8-4
modifying scripts, 13-67 execute button, 2-17
setting default file name, 13-105, 13-116 EXECUTE command, 13-69
Edit menu, 2-6
executing
EDITFILE variable, 13-105, 13-116
a CREATE command, 5-9
editor
statements, 5-3
defining, 2-6
executing scripts
invoking, 2-6 See running
registry entries, 3-29 execution plan, 9-4
EDITOR operating system variable, 13-54
execution statistics
EMBEDDED variable, 13-105, 13-116
including in report, 13-110
enabling iSQL*Plus, 3-24
EXIT clause
Enter statements field, 2-18, 2-19
WHENEVER OSERROR, 13-168
entities, HTML, 8-7 WHENEVER SQLERROR, 13-170
ENTMAP, 4-21 EXIT command, 4-17, 13-70
ENTMAP clause, 4-21, 8-7, 13-32
:BindVariable clause, 13-71
environment variables
COMMIT clause, 13-70
iSQL*Plus, 3-1
FAILURE clause, 13-70
LD_LIBRARY_PATH, 3-1
in a script, 13-147
LOCAL, 3-2
ROLLBACK clause, 13-71
NLS_LANG, 3-2 use with SET MARKUP, 8-2
ORA_NLS10, 3-2
WARNING clause, 13-70
ORACLE_HOME, 3-2
exit, conditional, 13-168
ORACLE_PATH, 3-2
exiting
ORACLE_SID, 3-2
iSQL*Plus, -xlii, 4-17
PATH, 3-2
SQL*Plus GUI, 2-5
SQL*Plus, 3-1 Expired Password screen, 4-4
SQLPATH, 3-2
extension, 13-101, 13-133, 13-152
SQLPLUS, 3-3
TNS_ADMIN, 3-3
TWO_TASK, 3-3 F
error messages FAILURE clause, 13-70
COPY command, 14-54 FEEDBACK variable, 13-105, 13-117
interpreting, 5-15 fields
iSQL*Plus, 14-45 connection identifier, 2-12, 2-15
sqlplus, 14-1 enter statements, 2-18, 2-19
errors new password, 4-3
Index-9
fields (continued) in ATTRIBUTE command, 13-18
password, 2-12, 2-15 in COLUMN command, 7-4, 7-6
privilege, 2-15 in REPHEADER and REPFOOTER
script location, 2-21 commands, 13-98
username, 2-12, 2-15, 4-3 in TTITLE and BTITLE commands, 7-30, 13-157
file extensions, 3-8, 13-101, 13-133, 13-152 format models, number, 7-4, 13-36
File menu, 2-4 formfeed, to begin a new page, 7-33, 13-123
file names FROM clause, 13-86, B-5
in @ ("at" sign) command, 13-6
in @@ (double "at" sign) command, 13-8
in EDIT command, 13-67
G
in GET command, 13-72 GET command, 13-72
in SAVE command, 13-101 LIST clause, 13-72
in SPOOL command, 7-36, 13-144 NOLIST clause, 13-72
in SQLPLUS command, 4-25 retrieving scripts, 13-72
files globalization support
flat, 7-35 Oracle10g, 12-5
finding text, 2-6 glogin
FLAGGER variable, 13-105, 13-118 profile, 13-131
flat file, 7-35 See also login.sql
FLUSH variable, 9-12, 13-105, 13-118 site profile, xxxi, xxxiv, 3-5, 3-6, 3-8, 4-23, 9-4,
FOLD_AFTER clause, 13-33 9-8, 10-12, 13-131, 13-137
FOLD_BEFORE clause, 13-33 GRANT command, 10-1
font disabling, 10-5
changing face and size in command-line, 2-2 graphical user interface
changing face and size in GUI, 2-8, 2-9 See GUI
changing in GUI, 2-8 GUI
euro sign in command-line, 2-2 changing face and size, 2-8, 2-9
fixed pitch TrueType, 2-8 changing font, 2-8
Oracle Database home, 2-9 menus, 2-4
setting default in GUI, 3-30 Windows Character Map utility, 2-10
setting default size in GUI, 3-30
special character in command-line, 2-2 H
Windows Character Map utility, 2-2
footers HEAD clause, 4-20
aligning elements, 13-98 HEAD option, 4-20
displaying at bottom of page, 13-95 headers
displaying system-maintained values, 13-97 aligning elements, 7-26
formatting elements, 13-98 displaying at top of page, 13-97
indenting, 13-98 displaying system-maintained values, 13-97
listing current definition, 13-95 setting at the start of reports, 7-24
setting at the end of reports, 7-24 suppressing, 7-26
suppressing definition, 13-98 HEADING clause, 7-2, 13-36
FORCE clause, 13-148 HEADING variable, 13-118
FORMAT clause, 13-11, 13-33
Index-10
headings accepting [Return], 6-31
aligning elements, 13-98 accepting values from the user, 6-28, 13-11
column headings, 13-118 INPUT command, 6-4, 6-8, 13-77
formatting elements, 13-98 entering several lines, 13-77
indenting, 13-98 INSERT clause, B-3, B-7
listing current definition, 13-97 INSERT command, disabling, 10-5
suppressing definition, 13-98 INSTANCE variable, 13-105, 13-119
HEADSEP variable, 13-105, 13-119 instances
use in COLUMN command, 7-2 shutting down, 13-142
help starting, 13-148
enabling or disabling iSQL*Plus help, 3-24 iSQL*Plus
installing command-line, 3-10 access modes, 10-11
iSQL*Plus online, 4-16 Application Server running, 3-14
menu, 2-8 Change Password screen, 4-2
online, 13-74 configuring Oracle Net, 3-12
HELP command, ? command, 13-74 DBA Login screen, 2-13
help, online, 4-9 dynamic reports, 8-8
HIDE clause, 13-12 enabling cookies, 3-25
History screen, 2-18 enabling javascript, 3-25
HOST command, 5-13, 13-75 enabling or disabling, 3-24
host string, 4-10 enabling or disabling iSQL*Plus help, 3-24
HTML, 8-2 enabling restricted database access, 3-16
clause, 4-20 environment variables, 3-1
entities, 3-24, 8-7 error messages, 14-45
option, 4-20 exiting, -xlii, 4-17
running dynamic reports, 8-8 Expired Password screen, 4-4
spooling to file, 4-22 History screen, 2-18
tag, 8-1 language support, 4-16
HTTP logging, 3-15
Application Server HTTP port, 4-12 Login screen, 2-12, 4-13
HTTPS security, 10-11 online help, 4-16
security, 10-10 port conflict, 3-12
hyphen Preferences screen, 2-20
continuing a long SQL*Plus command, 5-11, retained session settings, 3-25
13-1 security, 10-10
session-timeout, 3-15
setting up SSL, 3-21
I starting, 4-11, 4-14
IMMEDIATE mode, 13-142 starting from a URL, 4-14
infinity sign (~), 13-36 stopping, 4-13
initialization parameters substitution variables, 6-24
displaying, 13-137 three-tier model, 1-2
INIT.ORA file user access, 10-11
parameter file, 13-148 user interface, 1-2, 1-3
input Workspace, 2-16
Index-11
iSQL*Plus DBA URL, 3-17 LINESIZE variable, 7-26, 7-34, 13-105, 13-120
iSQLPlusAllowUserMarkup LIST clause, 13-14, 13-72
configuration parameter, 3-4, 3-24 LIST command, 6-4, 13-79
iSQLPlusConnectIdList determining current line, 6-5, 13-79
configuration parameter, 3-4, 3-16 making last line current, 6-5, 13-79
isqlplusctl using an asterisk, 6-4, 13-79
starting Application Server, 4-11 LNO clause, 13-137
load script button, 2-17
LOBOFFSET variable, 13-105, 13-120
J LOCAL
JAAS, 3-17 environment variables, 3-2
Japanese LOCK TABLE command
Java Authentication and Authorization Service disabling, 10-5
(JAAS), 3-17 log in button, 2-13, 2-15
Java AuthoriZatioN (JAZN), 3-17 Log On dialog, 4-9
javascript, configuring for iSQL*Plus, 3-25 LOG_ARCHIVE_DEST parameter, 13-14
JAZN, 3-17, 10-11 log4j.rootLogger, 3-15
Server authentication, 10-11 configuration parameter, 3-4
JUSTIFY clause, 13-36 LOGFILE clause, 13-87
logging, 3-15
L logging off
conditionally, 13-168, 13-170
LABEL variable Oracle Database, 4-2, 13-66
SHOW command, C-2, C-5 SQL*Plus, 4-17, 13-70
labels logging on
in COMPUTE command, 7-18, 13-43 Oracle Database, 13-48
language support in iSQL*Plus, 4-16 SQL*Plus, 4-8
LD_LIBRARY_PATH login, user profile, 3-7
environment variables, 3-1 Login screen, 2-12, 2-14, 3-16, 4-13
LEFT clause, 7-27, 13-98, 13-156 login.sql, 3-7
LIKE clause, 7-9, 13-18, 13-36 See glogin.sql
limits, SQL*Plus, A-1 Logout, -xlii, 4-17
line numbers, for SQL commands, 5-5 LONG
lines column definition from DESCRIBE, 13-59
adding at beginning of buffer, 13-77 LONG columns
adding at end of buffer, 13-77 changing format, 13-33
adding new after current, 6-8, 13-77 default format, 13-33
appending text to, 6-7, 13-13 setting maximum width, 13-105, 13-121
changing width, 7-34, 9-13, 13-105, 13-120 setting retrieval size, 9-13, 13-105, 13-121
deleting all in buffer, 13-57 LONG variable, 13-105, 13-121
deleting from buffer, 6-9, 13-57 effect on COPY command, B-3, B-8
determining which is current, 6-5 LONGCHUNKSIZE variable, 7-6, 13-33, 13-105,
editing current, 6-5 13-121, 13-122
listing all in buffer, 6-4, 13-79 LONGRAW
removing blanks at end, 13-135 column definition from DESCRIBE, 13-59
Index-12
M NEWLINE clause, 13-37
NEWPAGE command, C-1, C-3
-MARKUP, 4-19, 8-1
NEWPAGE variable, 7-33, 13-105, 13-123
SQLPLUS command clause, 4-20 NEXT clause, 13-15
MARKUP, 4-19, 8-1, 13-122 NLS
BODY clause, 4-20
NLS_DATE_FORMAT, 13-12, 13-40
ENTMAP clause, 4-21
NLS_LANG
HEAD clause, 4-20
environment variables, 3-2
PREFORMAT clause, 4-22
NOAUDIT command, disabling, 10-5
TABLE clause, 4-20 NOLIST clause, 13-72
MAXDATA variable, C-2, C-4 NOLOG, 4-6, 4-25
media recovery, 13-149
NOMOUNT clause, 13-149
menus, Windows GUI, 2-4
NONE clause
message logging, 3-15
WHENEVER OSERROR, 13-168
message, sending to screen, 6-28, 13-84
WHENEVER SQLERROR, 13-170
middle tier, 1-2 NOPARALLEL clause, 13-89
MOUNT clause, 13-149 NOPRINT clause, 7-18, 7-31, 9-12, 13-37
mounting a database, 13-149
NOPROMPT clause, 13-12
mouse, using to copy command, 2-3
NORMAL mode, 13-142
multiple Oracle Database homes, specifying
Notepad on Windows, 13-54
font, 2-9
NULL clause, 13-37
null values
N setting text displayed, 13-37, 13-105, 13-124
NULL variable, 13-105, 13-124
national language support
NUMBER
See also globalization support
column definition from DESCRIBE, 13-59
NCHAR clause
NUMBER clause, 6-30
VARIABLE command, 13-160
VARIABLE command, 13-160
NCHAR columns
NUMBER columns
changing format, 13-33
changing format, 7-4, 13-34
default format, 7-6, 13-33
default format, 7-4, 13-36
NCLOB clause
number formats
VARIABLE command, 13-161
$, 7-5
NCLOB columns
0, 7-5
changing format, 13-33
9, 7-5
default format, 13-33
comma, 7-5
setting maximum width, 13-105, 13-121
setting default, 6-23, 13-106, 13-124
setting retrieval position, 13-105, 13-120
NUMFORMAT clause
setting retrieval size, 9-13, 13-105, 13-121
in LOGIN.SQL, 3-8
negative infinity sign (-~), 13-36
NUMFORMAT variable, 13-106, 13-124
net service name, 4-5, 4-6
NUMWIDTH variable, 13-106, 13-124
See also connection identifier
effect on NUMBER column format, 7-4, 13-36
new password field, 4-3
NVARCHAR2 columns
NEW_VALUE clause, 7-31, 13-37
changing format, 13-33
storing current date in variable for titles, 13-37
default format, 7-6, 13-33
Index-13
O opening a database, 13-149
operating system
objects, describing, 13-115
editor, 6-2, 13-54, 13-67
obsolete commands file, loading into buffer, 13-72
BTITLE, C-2 running commands from SQL*Plus, 5-13, 13-75
COLUMN command DEFAULT clause, C-2
text editor, 6-2
DOCUMENT, C-1, C-3
Options menu, 2-7
NEWPAGE, C-1, C-3
ORA_NLS10
SET command BUFFER variable, C-3
environment variables, 3-2
SET command CLOSECURSOR variable, C-2, Oracle Database home
C-4 specifying font, 2-9
SET command DOCUMENT variable, C-2, C-4
Oracle Net, 1-3, 3-24, 10-11
SET command MAXDATA variable, C-2, C-4
configuring, 3-12
SET command SCAN variable, C-2, C-4
connect identifier, 13-48
SET command SPACE variable, C-2, C-4
security, 10-10
SET command TRUNCATE variable, C-2, C-5 ORACLE_HOME
SHOW command LABEL variable, C-2, C-5 environment variables, 3-2
TTITLE command old form, C-5
ORACLE_PATH
OF clause, 7-17
environment variables, 3-2
OFF clause, 13-38
ORACLE_SID
in ATTRIBUTE command, 13-18
environment variables, 3-2
in COLUMN command, 7-10, 13-38 Oracle10g, 1-3
in REPFOOTER commands, 13-98 globalization support, 12-5
in REPHEADER commands, 13-98
ORDER BY clause
in SPOOL command, 7-35, 13-144
displaying column values in titles, 7-31
in TTITLE and BTITLE commands, 7-30, 13-156
displaying values together in output, 7-12
OLD_VALUE clause, 7-32, 13-38
OUT clause, 7-36, 13-144
ON clause
output
in ATTRIBUTE command, 13-18 formatting white space in, 9-14, 13-134
in COLUMN command, 7-10, 13-38
pausing during display, 5-13, 13-125
in TTITLE and BTITLE commands, 7-31
ON column clause
in BREAK command, 7-13, 13-19 P
in COMPUTE command, 7-17, 13-43 PAGE clause, 13-97
ON expr clause page number, including in titles, 7-15, 7-29
in BREAK command, 13-20 pages
in COMPUTE command, 13-43 changing length, 7-33, 9-13, 13-106, 13-124
ON REPORT clause default dimensions, 7-33
in BREAK command, 7-21, 13-21 matching to screen or paper size, 7-33
in COMPUTE command, 7-21, 13-43 setting dimensions, 7-33
ON ROW clause PAGESIZE clause
in BREAK command, 7-15, 13-21 in LOGIN.SQL, 3-8
in COMPUTE command, 13-43 PAGESIZE variable, 5-6, 7-33, 9-13, 13-106, 13-124
online help, 4-9, 13-74
OPEN clause, 13-149
Index-14
parameter, 6-26, 13-6, 13-146 pound sign (#), 13-36
iSQL*Plus session-timeout, 3-15 predefined variable
iSQLPlusAllowUserMarkup, 3-24 _CONNECT_IDENTIFIER, xxxii, 3-8, 13-53
SQLPATH, 3-29 _DATE, 13-53
SQLPLUS_FONT, 2-8, 3-30 _EDITOR, 2-6, 6-2, 13-53, 13-54, 13-67, 13-68
SQLPLUS_FONT_SIZE, 2-8, 3-30 _O_RELEASE, 13-53, 13-54
parameter files (INIT.ORA files) _O_VERSION, 13-53, 13-54
specifying alternate, 13-148 _PRIVILEGE, xxxii, 13-53, 13-54
PARAMETERS clause, 13-137 _RC, 13-75
password _SQLPLUS_RELEASE, 13-53, 13-55, 13-56
Application Server authentication, 2-14 _USER, 13-53, 13-55
changing in iSQL*Plus, 4-2, 4-4 Preferences screen, 2-20
changing with the PASSWORD PREFORMAT, 4-22
command, 13-81 PREFORMAT clause, 4-22
field, 2-12, 2-15 PRINT clause, 13-37
in CONNECT command, 4-2, 13-48 PRINT command, 13-83
in COPY command, B-5, B-7, B-9 printing
in SQLPLUS command, 4-8, 4-24 bind variables automatically, 13-109
viewable warning, 4-24 REFCURSOR variables, 13-163
PASSWORD command, 13-48, 13-81 SPOOL command, 13-144
pasting text, 2-6 privileges
PATH list, 2-15
environment variables, 3-2 Product User Profile table, 10-1, 10-12
PAUSE command, 6-31, 13-82 prompt
PAUSE variable, 5-13, 13-106, 13-125 SET SQLPROMPT, 9-13, 13-106, 13-132
performance PROMPT clause, 6-28, 13-12
of SQL statements, 9-1 PROMPT command, 6-28, 13-84
over dial-up lines, 13-135 customizing prompts for value, 6-29
period (.) prompts for value
terminating PL/SQL blocks, 5-8, 13-104, 13-111 bypassing with parameters, 6-26
PLAN_TABLE customizing, 6-29
creating, 9-2 through ACCEPT, 6-28
table, 9-2 through substitution variables, 6-17
PL/SQL, 5-8 PUPBLD.SQL, 10-2
blocks, PL/SQL, 5-8
executing, 13-69
formatting output in SQL*Plus, 13-162
Q
listing definitions, 5-5 queries
mode in SQL*Plus, 5-9 in COPY command, B-3, B-6
within SQL commands, 5-9 show number of records retrieved, 5-6, 13-105,
PLUSTRACE 13-117
creating role, 9-3 tracing, 9-8
role, 9-2 query execution path
PNO clause, 13-138 including in report, 13-110
port conflict, 3-12
Index-15
query results registry entry
displaying on-screen, 5-5 SQLPATH, 3-2, 3-29
sending to a printer, 7-36, 13-144 SQLPLUS_FONT, 2-8, 3-3, 3-30
storing in a file, 7-36, 13-144 SQLPLUS_FONT_SIZE, 2-8, 3-3, 3-30
QUIT command, 13-70 RELEASE clause, 13-138
See also EXIT REMARK command, 6-10, 13-94
removing sample tables, 1-6
RENAME command
R disabling, 10-5
RAW REPFOOTER clause, 13-138
column definition from DESCRIBE, 13-59 REPFOOTER command, 7-24, 13-95
record separators, printing, 7-10, 13-106, 13-125 aligning footer elements, 13-98
RECOVER clause, 13-149 BOLD clause, 13-98
RECOVER command, 13-85 CENTER clause, 13-98
and database recovery, 11-5 COL clause, 13-98
AUTOMATIC clause, 13-86 FORMAT clause, 13-98
CANCEL clause, 13-87, 13-91 indenting report footers, 13-98
CONTINUE clause, 13-87 LEFT clause, 13-98
DATABASE clause, 13-88 OFF clause, 13-98
FROM clause, 13-86 RIGHT clause, 13-98
LOGFILE clause, 13-87 SKIP clause, 13-98
NOPARALLEL clause, 13-89 suppressing current definition, 13-98
STANDBY DATABASE clause, 13-88 TAB clause, 13-98
STANDBY DATAFILE clause, 13-89 REPHEADER clause, 13-138
STANDBY TABLESPACE clause, 13-88, 13-89 REPHEADER command, 7-24, 13-97
UNTIL CANCEL clause, 13-88 aligning header elements, 7-26
UNTIL CONTROLFILE clause, 13-89 aligning heading elements, 13-98
UNTIL TIME clause, 13-88 BOLD clause, 13-98
USING BACKUP CONTROL FILE clause, 13-88 CENTER clause, 13-98
recovery COL clause, 13-98
RECOVER command, 13-85 FORMAT clause, 13-98
RECSEP variable, 7-10, 13-106, 13-125 indenting headings, 13-98
RECSEPCHAR variable, 7-10, 13-106, 13-125 LEFT clause, 13-98
redo Log Files OFF clause, 13-98
ARCHIVE LOG command, 13-14 PAGE clause, 13-97
REFCURSOR bind variables RIGHT clause, 13-98
in a stored function, 6-33 SKIP clause, 13-98
REFCURSOR clause suppressing current definition, 13-98
VARIABLE command, 13-161 TAB clause, 13-98
REGEDIT.EXE, 3-29 REPLACE clause
REGEDT32.EXE, 3-29 in COPY command, B-3, B-6
registry in SAVE command, 13-101, 13-144
editor, 2-8, 3-29, 3-30
REGEDIT.EXE, 3-29
REGEDT32.EXE, 3-29
Index-16
reports Run menu command, 2-5
autotrace, 9-2
breaks, 13-19
clarifying with spacing and summary lines, 7-12
S
columns, 13-32 sample schemas, xxiv, -xl, 1-5, 1-6, 8-8
creating bottom titles, 7-24, 13-24, C-1 see Oracle Database Sample Schemas guide, -xl
creating dynamic, 8-8 see Oracle9i Sample Schemas guide, 1-5
creating footers, 13-95 using HR in COLUMN example, 13-40
creating headers, 13-97 using HR in examples, 6-1, 7-1
creating headers and footers, 7-24 sample tables
creating master/detail, 7-31, 13-37, 13-38 access to, 1-6
creating top titles, 7-24, 13-155, C-2 creating, 1-6
displaying, 13-104, 13-110 removing, 1-6
formatting column headings, 7-2, 13-31 unlocking, -xl, 1-6
formatting columns, 7-4, 7-6, 13-31 SAVE command, 13-101
interactive HTML example, 8-2, 8-4 APPEND clause, 13-101
on the web, 8-1 CREATE clause, 13-101
running from a URL, 8-8 REPLACE clause, 13-101
SILENT mode, 8-6 storing commands in scripts, 13-101
starting on a new page, 13-116 using with INPUT to create scripts, 6-3
title, 13-155, C-2 save script button, 2-17
RESTRICT, 4-23, 10-9, 13-148 saving environment attributes, 13-152
restricted database access, 3-16 saving, command files, 2-4
return code, specifying, 6-15, 13-71, 13-171 SCAN variable, C-2, C-4
REVOKE command, 10-1 schemas
disabling, 10-5 command, 14-15
RIGHT clause, 7-27, 13-98, 13-156 database, 9-2
roles, 10-7 database default, 13-49
disabling, 10-8 DESCRIBE parameter, 13-59
re-enabling, 10-8 disabled commands, 14-20
ROLLBACK clause, 13-71 HR sample, -xl, 1-5
WHENEVER OSERROR, 13-168 installing own copy of HR, 1-6
WHENEVER SQLERROR, 13-170 sample, xxiv
ROWID SHOW parameter, 13-136
column definition from DESCRIBE, 13-59 unlocking HR, -xl, 1-6
rows using HR in COLUMN example, 13-40
performing computations on, 7-17, 13-42 using HR in examples, 6-1, 7-1, 8-8
setting number retrieved at one time, 9-12, screen buffer area, 2-7
13-104, 13-109 SCREEN clause, 6-31, 13-30
setting the number after which COPY screens
commits, 13-114 Change Password, 4-2
RUN command, 13-100 clearing, 6-31, 13-30
executing current PL/SQL block, 5-8 connection identifier field, 2-12, 2-15
making last line current, 6-5 DBA Login, 2-13
similar to / (slash) command, 13-100 DBA Workspace, 2-17
Index-17
screens (continued) service name
enter statements field, 2-18, 2-19 in COPY command, B-5, B-7, B-9
Expired Password, 4-4 session
History, 2-18 identification, 4-13
Login, 2-12, 2-14 settings, 3-25
new password field, 4-3 stateful behavior, 3-25
password field, 2-12, 2-15 session-timeout parameter, 3-15
Preferences, 2-20 SET AUTOTRACE, 9-2
privilege list, 2-15 SET clause, 13-152
script location field, 2-21 SET command, 3-8, 5-12, 13-103
username field, 2-12, 2-15, 4-3 APPINFO variable, 9-12, 13-107
Workspace, 2-16 ARRAYSIZE variable, 9-12, 13-104, 13-109, B-8
scripts AUTOCOMMIT variable, 13-104, 13-109
extension, 13-101, 13-133, 13-152 AUTOPRINT variable, 13-104, 13-109, 13-162
location field, 2-21 AUTORECOVERY variable, 13-104, 13-110
registering, 9-12 AUTOTRACE variable, 13-104, 13-110
See also command file BLOCKTERMINATOR variable, 13-104, 13-111
Search menu, 2-6 BUFFER variable, C-3
Secure Sockets Layer security, 10-11 CLOSECURSOR variable, C-2, C-4
security CMDSEP variable, 13-104, 13-111
Application Server, 10-11 COLSEP variable, 7-36, 13-104, 13-112
changing password, 13-81 COMPATIBILITY variable, 13-104, 13-113
HTTP, 10-10 CONCAT variable, 6-23, 13-104, 13-114
Oracle Net, 10-10 COPYCOMMIT variable, 13-104, 13-114, B-8
password viewable, 4-24 COPYTYPECHECK variable, 13-104, 13-114
PRODUCT_USER_PROFILE table, 10-1 DEFINE clause, 6-23
RESTRICT, 4-23, 10-9 DEFINE variable, 13-104
Secure Sockets Layer (SSL), 10-11 DESCRIBE variable, 13-104, 13-115
SELECT command DOCUMENT variable, C-2, C-4
and BREAK command, 7-12, 13-20, 13-21 ECHO variable, 13-105, 13-116
and COLUMN command, 13-32 EDITFILE variable, 13-105, 13-116
and COMPUTE command, 7-12 EMBEDDED variable, 13-105, 13-116
and COPY command, B-3, B-6 ESCAPE variable, 6-23, 13-105, 13-117
and DEFINE command, 13-51 FEEDBACK variable, 13-105, 13-117
and ORDER BY clause, 7-12 FLAGGER variable, 13-105, 13-118
formatting results, 6-33 FLUSH variable, 9-12, 13-105, 13-118
semicolon (;) HEADING variable, 13-118
in PL/SQL blocks, 5-8 HEADSEP variable, 7-2, 13-105, 13-119
in SQL commands, 5-5, 5-7 INSTANCE variable, 13-105, 13-119
in SQL*Plus commands, 5-11, 13-1 LINESIZE variable, 7-26, 7-34, 13-105, 13-120
not stored in buffer, 6-5 LOBOFFSET variable, 13-105, 13-120
server LOGSOURCE variable, 13-105, 13-121
authentication, 10-11 LONG variable, 13-105, 13-121, B-8
iSQL*Plus port conflict, 3-12 LONGCHUNKSIZE variable, 13-105, 13-121
SERVEROUTPUT variable, 13-126 MARKUP clause, 13-122
Index-18
SET command (continued) interactive HTML example, 8-2, 8-4
MAXDATA variable, C-2, C-4 PREFORMAT clause, 4-22
NEWPAGE variable, 7-33, 13-105, 13-123 See also SPOOL command
NULL variable, 13-105, 13-124 TABLE clause, 4-20
NUMFORMAT clause, 3-8 Set Options area, 2-7
NUMFORMAT variable, 13-106, 13-124 SET ROLE command
NUMWIDTH variable, 7-4, 13-36, 13-106, 13-124 disabling, 10-5
PAGESIZE clause, 3-8 SET system variable summary, 13-104
PAGESIZE variable, 5-6, 7-33, 9-13, 13-106, SET TRANSACTION command
13-124 disabling, 10-5
PAUSE variable, 13-106, 13-125 SET variables, 5-12
RECSEP variable, 7-10, 13-106, 13-125 See system variables
RECSEPCHAR variable, 7-10, 13-106, 13-125 SGA clause, 13-139
SCAN variable, C-2, C-4 SHIFTINOUT variable, 13-106, 13-128
SERVEROUTPUT variable, 13-126 SHOW
SHIFTINOUT variable, 13-106, 13-128 schema parameter, 13-136
SPACE variable, C-2, C-4 SHOW clause, 13-153
SQLBLANKLINES variable, 13-129 SHOW command, 5-12, 13-136
SQLCASE variable, 13-106, 13-129 ALL clause, 13-136
SQLCONTINUE variable, 13-106, 13-130 BTITLE clause, 13-136
SQLNUMBER variable, 13-106, 13-130 ERRORS clause, 13-137
SQLPLUSCOMPATIBILITY variable, 13-106, LABEL variable, C-2, C-5
13-130 listing current page dimensions, 7-35
SQLPREFIX variable, 13-106, 13-132 LNO clause, 13-137
SQLPROMPT variable, 9-13, 13-106, 13-132 PNO clause, 13-138
SQLTERMINATOR variable, 13-106, 13-133 RELEASE clause, 13-138
substitution variable, 13-114 REPFOOTER clause, 13-138
SUFFIX variable, 13-106, 13-133 REPHEADER clause, 13-138
TAB variable, 9-14, 13-107, 13-134 SPOOL clause, 13-139
TERMOUT variable, 9-14, 13-107, 13-134 SQLCODE clause, 13-139
TIME variable, 13-107, 13-134 TTITLE clause, 13-139
TIMING variable, 13-107, 13-134 USER clause, 13-139
TRIMOUT variable, 13-107, 13-135 SHOWMODE variable, 13-106, 13-128
TRIMSPOOL variable, 13-107, 13-135 SHUTDOWN command, 13-142
TRUNCATE variable, C-2, C-5 ABORT, 13-142
UNDERLINE variable, 13-107, 13-135 IMMEDIATE, 13-142
used to format a REFCURSOR variable, 13-163 NORMAL, 13-142
VERIFY clause, 6-18 TRANSACTIONAL LOCAL, 13-142
VERIFY variable, 6-23, 13-107, 13-135 -SILENT option, 4-24, 8-6
WRAP variable, 7-7, 13-107, 13-135 site profile
SET MARKUP glogin, xxxi, xxxiv, 3-5, 3-6, 3-8, 4-23, 9-4, 9-8,
BODY clause, 4-20 10-12, 13-131, 13-137
ENTMAP clause, 4-21, 8-7
HEAD clause, 4-20
HTML, 4-20
Index-19
SKIP clause obsolete command alternatives, C-1
in BREAK command, 7-14, 7-15, 13-21 setting up environment, 3-4
in REPHEADER and REPFOOTER shortcuts to starting, 4-9
commands, 13-98 starting, 4-7, 4-8, 4-18
in TTITLE and BTITLE commands, 7-27, 13-156 statistics, 9-4
used to place blank lines before bottom system variables affecting performance, 9-11
title, 7-27 tuning, 9-1
SKIP PAGE clause, 7-14, 7-15, 13-21 who can use, 1-4
slash (/) command, 13-10 SQL*Plus Windows GUI
files loaded with GET command, 13-73 changing face and size, 2-8, 2-9
SPACE variable, C-2, C-4 changing font, 2-8
special characters SQLBLANKLINES variable, 13-106, 13-129
choosing a font, 2-2 SQLCASE variable, 13-106, 13-129
Euro sign, 2-2, 2-9, 2-10 SQLCODE clause, 13-139
using, 2-2, 2-10 SHOW command, 13-139
SPOOL clause, 4-21, 13-139 SQLCONTINUE variable, 13-106, 13-130
SPOOL command, 7-35, 13-144 SQL.PNO, referencing in report titles, 7-29
APPEND clause, 13-144 SQL.SQLCODE
CREATE clause, 13-144 using in EXIT command, 13-70
file name, 7-36, 13-144 SQLNUMBER variable, 13-106, 13-130
OFF clause, 7-35, 13-144 SQLPATH
OUT clause, 7-36, 13-144 environment variables, 3-2
REPLACE clause, 13-144 registry entry, 3-2, 3-29
to HTML file, 4-22 SQLPLUS
turning spooling off, 7-35, 13-144 environment variables, 3-3
use with SET MARKUP, 8-2 SQLPLUS command, 4-8
spool menu command, 2-5 - clause, 4-19
SQL buffer, 2-5 -? clause, 4-19
SQL clause, 13-30 and @ ("at" sign), 4-18
SQL DML statements and EXIT FAILURE, 4-16
reporting on, 13-104, 13-110 BODY option, 4-20
SQL optimizer, 9-4 commands
SQL*Plus SQLPLUS, 4-18
application window, 2-3, 4-10 connect identifier, 4-25
command prompt, 4-8 display syntax, 4-19
command summary, 13-2 ENTMAP option, 4-21
configuring globalization support, 12-2 HEAD option, 4-20
database administration, 11-1 HTML option, 4-20
environment variables, 3-1 -MARKUP clause, 4-20
error messages, 14-1 -MARKUP option, 4-19
execution plan, 9-4 /NOLOG clause, 4-25
exiting, 4-17, 13-70 PREFORMAT option, 4-22
exiting conditionally, 13-168 RESTRICT, 4-23, 10-9
limits, A-1 service name, 4-25
menus, 2-4 -SILENT clause, 4-24
Index-20
SQLPLUS command (continued) specifying a database, 13-149
-SILENT option, 4-24, 8-6 statements
SPOOL clause, 4-21 executing, 5-3
syntax, 4-18 statistics, 9-4
SYSDBA clause, 4-25 collecting TIMING statistics, 9-8
TABLE option, 4-20 STOP clause, 13-15, 13-153
unsuccessful connection, 4-16 stop query, 5-12
username/password, 4-8, 4-24 stopping
SQLPLUS_FONT iSQL*Plus Application Server, 4-13
registry entry, 2-8, 3-3, 3-30 STORE command, 3-8, 13-152
SQLPLUS_FONT_SIZE SET clause, 13-152
registry entry, 2-8, 3-3, 3-30 stored functions, 6-33
SQLPREFIX variable, 13-106, 13-132 stored procedures
SQLPROMPT variable, 9-13, 13-106, 13-132 creating, 5-9
SQLTERMINATOR variable, 13-75, 13-106, 13-129, subkey, registry, 3-29, 3-30
13-133 substitution variables, 6-16, 6-17, 6-23, 13-104,
SSL 13-114
iSQL*Plus setup, 3-21 _EDITOR, 13-54
security, 10-11 appending characters immediately after, 6-19
STANDBY DATAFILE clause, 13-89 avoiding unnecessary prompts for value, 6-20
STANDBY TABLESPACE clause, 13-88 concatenation character, 13-104, 13-114
START clause, 13-15, 13-153 DEFINE command, 13-51
START command, 6-13, 13-146 defining, 6-16, 6-20, 13-51
arguments, 6-26 deleting, 6-16, 13-159
passing parameters to a script, 6-26 displaying in headers and footers, 13-97
script, 6-13, 13-146 displaying in titles, 13-155
similar to @ ("at" sign) command, 6-14, 13-6, in ACCEPT command, 6-28, 13-11
13-147 iSQL*Plus, 6-24
similar to @@ (double "at" sign) listing definitions, 6-16, 13-51
command, 13-147 parsing, 9-12
Start menu prefixing, 13-114, C-2
starting SQL*Plus, 4-9 related system variables, 6-23
starting restrictions, 6-23
iSQL*Plus, 4-11, 4-14 single and double ampersands, 6-20
SQL*Plus, 2-1, 4-7, 4-8 system variables used with, 6-23
SQL*Plus shortcuts, 4-9 undefined, 6-17
SQL*Plus Windows GUI, 4-9 where and how to use, 6-17
STARTUP command, 13-148 SUFFIX variable, 13-106, 13-133
FORCE clause, 13-148 used with EDIT command, 13-67
MOUNT clause, 13-149 used with GET command, 13-72
NOMOUNT clause, 13-149 used with SAVE command, 13-101
OPEN clause, 13-149 used with START command, 13-146
PFILE clause, 13-148 SUM function, 7-17
RECOVER clause, 13-149
RESTRICT clause, 13-148
Index-21
summary lines tag, HTML, 8-1
computing and printing, 7-17, 13-42 TERMOUT variable, 9-14, 13-107, 13-134
computing and printing at ends of reports, 7-21 using with SPOOL command, 13-145
computing same type on different text, 4-20
columns, 7-22 adding to current line with APPEND, 6-7, 13-13
printing "grand" and "sub" summaries changing old to new with CHANGE, 6-5, 13-26
(totals), 7-21 clearing from buffer, 6-3, 13-29
printing multiple on same break column, 7-22 text editor
syntax defining, 2-6
COPY command, B-5 invoking, 2-6
syntax rules operating system, 6-2, 13-67
SQL commands, 5-6 three-tier model, 1-2
SQL*Plus commands, 5-11 TIME variable, 13-107, 13-134
SYSDBA clause, 13-49 TIMING clause, 13-30
SYSOPER clause, 4-25, 13-49 TIMING command, 9-8, 13-153
system variables, 5-12, 13-103 deleting all areas created by, 13-30
affecting SQL*Plus performance, 9-11 deleting current area, 13-153
affecting substitution variables, 6-23 SHOW clause, 13-153
listing current settings, 5-12, 13-136 START clause, 13-153
listing old and new values, 13-106, 13-128 STOP clause, 13-153
screen buffer, 2-7 TIMING variable, 13-107, 13-134
Set Options area, 2-7 titles
setting, 2-7 aligning elements, 7-26, 13-156
storing and restoring, 3-8 displaying at bottom of page, 7-24, 13-24, C-1
summary of SET commands, 13-104 displaying at top of page, 7-24, 13-155, C-2
value area, 2-7 displaying column values, 7-31, 13-37, 13-38
system-maintained values displaying current date, 7-32, 13-37, 13-40
displaying in headers and footers, 13-97 displaying page number, 7-29, 13-158
displaying in titles, 7-29, 13-155 displaying system-maintained values, 7-29,
formatting in titles, 7-30 13-155
formatting elements, 13-157
formatting system-maintained values in, 7-30
T indenting, 7-28, 13-156
TAB clause, 13-98, 13-156 listing current definition, 7-30, 13-24, 13-157
TAB variable, 9-14, 13-107, 13-134 restoring definition, 7-31
TABLE clause, 4-20 setting at start or end of report, 7-24
TABLE option, 4-20 setting lines from top of page to top title, 7-33,
tables 13-105, 13-123, C-1
access to sample, 1-6 setting lines from top title to end of page, 9-13,
controlling destination when copying, B-2, B-6 13-106, 13-124
copying values between, B-4, B-9 setting top and bottom, 7-24, 13-24, 13-155, C-1,
listing column definitions, 5-4, 13-59 C-2
referring to another user’s when copying, B-9 spacing between last row and bottom title, 7-27
TABLESPACE clause, 13-88 suppressing definition, 7-30, 13-156
tablespaces, recovering, 13-86
Index-22
TNS_ADMIN U
environment variables, 3-3
UNDEFINE command, 6-16, 13-159
TO clause, B-5
tracing queries, 9-8 and DEFINE command, 13-51
tracing statements UNDERLINE variable, 13-107, 13-135
unicode
for performance statistics, 9-5
UNIX
for query execution path, 9-5
ed, 13-54
using a database link, 9-7
unlocking sample tables, -xl, 1-6
with parallel query option, 9-9
TRIMOUT variable, 13-107, 13-135 UNTIL CANCEL clause, 13-88
TRIMSPOOL variable, 13-107, 13-135 UNTIL CHANGE clause, 13-88
UNTIL CONTROLFILE clause, 13-89
TRUNCATE command
UNTIL TIME clause, 13-88
disabling, 10-5
UPDATE command, disabling, 10-5
TRUNCATE variable, C-2, C-5
URL
TRUNCATED clause, 7-7, 13-38
TTITLE clause, 13-139 running dynamic reports, 8-8
TTITLE command, 7-24, 13-155 starting iSQL*Plus, 4-14
USER clause, 13-139
aligning title elements, 7-26, 13-156
user profile, 3-7
BOLD clause, 13-157
glogin.sql, 3-7
CENTER clause, 7-27, 13-156
login.sql, 3-7
COL clause, 7-28, 13-156
FORMAT clause, 7-30, 13-157 See also site profile
indenting titles, 7-28, 13-156 user variable
See substitution variable
LEFT clause, 7-27, 13-156
username, 4-1
listing current definition, 7-30, 13-157
connecting under different, 4-2, 13-48
OFF clause, 7-30, 13-156
field, 2-12, 2-15, 4-3
old form, C-5
in CONNECT command, 4-2, 13-48
ON clause, 7-31
referencing column value variable, 7-31, 13-37 in COPY command, B-5, B-7, B-9
in SQLPLUS command, 4-8, 4-24
restoring current definition, 7-31
USING BACKUP CONTROL FILE clause, 13-88
RIGHT clause, 7-27, 13-156
USING clause, B-3, B-6
SKIP clause, 7-27, 13-156
UTF-8
suppressing current definition, 7-30, 13-156
TAB clause, 13-156
tuning V
SET APPINFO OFF, 9-12
V$SESSION virtual table, 13-107
SET ARRAYSIZE, 9-12
V$SQLAREA virtual table, 13-107
SET DEFINE OFF, 9-12
value area, 2-7
SET FLUSH OFF, 9-12
value screen area, 2-7
SET TRIMOUT ON, 9-14
VARCHAR columns
SET TRIMSPOOL ON, 9-14
default format, 7-6
SQL*Plus, 9-1
VARCHAR2
system variables, 9-11
column definition from DESCRIBE, 13-59
TWO_TASK
environment variables, 3-3
Index-23
VARCHAR2 clause changing face and size, 2-8, 2-9
VARIABLE command, 13-161 changing font, 2-8
VARCHAR2 columns command keys, 2-4
changing format, 13-33 configuring, 3-26
default format, 7-6 exiting, 2-5
VARIABLE command, 13-160 File menu, 2-4
BINARY_DOUBLE clause, 13-162 Log On dialog, 4-9
BINARY_FLOAT clause, 13-161 menus, 2-4
CHAR clause, 13-160 starting SQL*Plus, 4-9
CLOB clause, 13-161 Windows service
NCHAR clause, 13-160 starting iSQL*Plus Application Server, 4-11
NCLOB clause, 13-161 WORD_WRAPPED clause, 7-7, 7-10, 13-38
NUMBER clause, 13-160 Workspace, 2-16
REFCURSOR clause, 13-161 WRAP variable, 7-7, 13-107, 13-135
VARCHAR2 clause, 13-161 WRAPPED clause, 7-7, 13-38
variable clause, 13-160
variables
bind variables, 6-32
X
substitution variables, 13-51 XMLType
system variables, 5-12 column definition from DESCRIBE, 13-59
VERIFY clause, 6-18 column formatting, 7-8
VERIFY variable, 6-23, 13-107, 13-135 column width, 7-6
creating, 7-8
formatting in reports, 7-6
W inserting values, 7-8
WARNING clause, 13-70 selecting data, 7-8
web browser, 1-2, 8-2 setting column retrieval size, 9-13, 13-121
web, outputting reports, 8-1 setting maximum column width, 13-121
WHENEVER OSERROR command, 13-168
COMMIT clause, 13-168
CONTINUE clause, 13-168
EXIT clause, 13-168
NONE clause, 13-168
ROLLBACK clause, 13-168
WHENEVER SQLERROR command, 13-170
COMMIT clause, 13-170
CONTINUE clause, 13-170
EXIT clause, 13-170
NONE clause, 13-170
ROLLBACK clause, 13-170
Windows
notepad, 13-54
Windows GUI
application window, 2-3, 4-10
cancelling, 2-5
Index-24