Tải bản đầy đủ (.pdf) (10 trang)

Oracle SQL Plus The Definitive Guide- P46 potx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (98.99 KB, 10 trang )

< previous page page_413 next page >
Page 413
SET SCAN {OFF¦ON}
SET SCAN
Is the command, which may not be abbreviated.
OFF
Disables variable substitution, and has the same effect as SET DEFINE OFF.
ON
Enables variable substitution, and has the same effect as SET DEFINE ON.
The SET SCAN command duplicates functionality provided by the SET DEFINE command.
Large Object Settings
Large object settings control the way SQL*Plus handles columns with a datatype of LONG. The most commonly
adjusted setting is the LONG setting, which controls the maximum number of characters SQL*Plus will display from a
LONG. The complete list of LONG settings is shown here:
LOBOFFSET
An index into the LONG column, specifying the first character to be displayed.
LONG
Specifies the maximum number of characters to display from a LONG column.
LONGCHUNKSIZE
Controls the number of characters retrieved from a LONG at one time.
Chapter 7, Advanced Scripting, contains examples showing how to use these three settings.
SET LOBOFFSET
The LOBOFFSET setting represents an index into a LONG column. When SQL*Plus displays a LONG, it begins with
the character pointed to by LOBOFFSET.
SET LOBOF[FSET] offset
where:
SET LOBOF[FSET]
Is the command, which may be abbreviated to SET LOBOF.
offset
Is the offset used when retrieving LONG values, and represents the first character you want to display.
Using the LOBOFFSET setting in conjunction with the LONG setting allows you to print any arbitrary substring from a


LONG column.

< previous page page_413 next page >
< previous page page_414 next page >
Page 414
SET LONG
The LONG setting controls the number of characters displayed by SQL*Plus from any LONG columns returned by a
query:
SET LONG long_length
where:
SET LONG
Is the command, which may not be abbreviated.
long_length
Represents the number of characters you want displayed from any LONG columns you select from the database. The
default setting is to display 80 characters.
SET LONGCHUNKSIZE
The LONGCHUNKSIZE is a performance-related setting. It controls the number of characters retrieved at one time
from a LONG column.
SET LONG[HUNKSIZE] size
where:
SET LONGC[HUNKSIZE]
Is the command, which may be abbreviated to SET LONGC.
size
Is the number of characters you want to retrieve from a LONG column in one fetch. The default value is 80.
With the default setting of 80 characters, SQL*Plus will need 10 round trips to the database to retrieve an 800-character
LONG value. These network round trips take time, so you will tend to get better performance by increasing this setting.
If you can afford the memory, make LONGCHUNKSIZE equal to the LONG setting. That way, the entire LONG value
will be retrieved in one fetch.
Tuning and Timing Settings
Two settings are useful when tuning SQL statements. They are:

AUTOTRACE
Enables the automatic display of the execution plan and execution statistics for a SQL statement.
TIMING
Controls whether or not SQL*Plus displays the elapsed execution time for each SQL statement or PL/SQL block.

< previous page page_414 next page >
< previous page page_415 next page >
Page 415
Chapter 8, Tuning and Timing, describes the timing features of SQL*Plus in detail, and also explains how to interpret
the execution plan for a SQL statement.
SET AUTOTRACE
The AUTOTRACE setting is used to control whether or not SQL*Plus displays the execution plan and statistics for
each SQL statement as it is executed:
SET AUTOT[RACE] {OFF¦ON¦TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]
where:
SET AUTOT[RACE]
Is the command, which may be abbreviated to SETAUTOT.
OFF
Disables the autotrace feature. SQL*Plus will not display the execution plan or the statistics for each SQL statement.
ON
Turns the autotrace feature on. If no other parameters are supplied, SQL*Plus will default to displaying the statistics.
SET AUTOTRACE ON is equivalent to SET AUTOTRACE ON STATISTICS.
TRACE[ONLY]
Inhibits the display of any data returned when the SQL statement in question is a SELECT statement.
EXP[LAIN]
Causes SQL*Plus to display the execution plan for each SQL statement you execute.
STAT[ISTICS]
Causes SQL*Plus to display execution statistics for each SQL statement you execute.
See Chapter 8 for comprehensive examples showing how to use the autotrace feature of SQL*Plus. Chapter 8 also
shows you how to interpret the execution plan output and describes the operations that may be used in that plan.

SET TIMING
The TIMING setting controls whether or not SQL*Plus displays the elapsed time for each SQL statement or PL/SQL
block you execute:
SET TIMI[NG] {OFF¦ON}
where:
SET TIMI[NG]
Is the command, which may be abbreviated to SET TIMI.

< previous page page_415 next page >
< previous page page_416 next page >
Page 416
OFF
Turns the timing feature off. This is the default setting.
ON
Enables the display of elapsed execution time for SQL statements and PL/SQL blocks.
See Chapter 8, for examples of this command.
Database Administration Settings
Database administration settings may be used only by database administrators, and control the way SQL*Plus operates
when performing administrative tasks such as database recovery. These settings are listed below:
AUTORECOVERY
Causes the RECOVER command to run without user intervention.
LOGSOURCE
Tells SQL*Plus where to find archive log files for recovery.
SET AUTORECOVERY
The AUTORECOVERY option causes the RECOVER command to run without user intervention, as long as the
archived log files are in the destination pointed to by the LOG_ARCHIVE_DEST parameter and the names conform to
the LOG_ARCHIVE_FORMAT parameter.
SET AUTORECOVERY {OFF¦ON}
where:
SET AUTORECOVERY

Is the command, which may not be abbreviated.
OFF
Turns autorecovery off. This is the default setting.
ON
Turns autorecovery on, causing the RECOVER command to run without user intervention.
Chapter 10, Administration with SQL*Plus, talks about recovery in more detail.
SET LOGSOURCE
The LOGSOURCE setting specifies the location of the archive log files, and is referenced during recovery:
SET LOGSOURCE logpath

< previous page page_416 next page >
< previous page page_417 next page >
Page 417
where:
SET LOGSOURCE
Is the command, which may not be abbreviated.
logpath
Is the path to the directory containing the archived redo log files.
Miscellaneous Settings
This section describes the following three miscellaneous settings:
COPYTYPECHECK
Controls whether or not type checking is done for the COPY command.
EDITFILE
Specifies the name of the work file used when you invoke the EDIT command.
INSTANCE
Specifies the default database instance to use with the CONNECT command.
SET COPYTYPECHECK
The COPYTYPECHECK setting controls whether or not SQL*Plus checks the datatypes when you use the COPY
command to move data between two databases:
SET COPYTYPECHECK {OFF¦ON}

where:
SET COPYTYPECHECK
Is the command, which may not be abbreviated.
OFF
Turns type checking off.
ON
Enables type checking. This is the default setting.
This option was created specifically for use when copying data to a DB2 database.
SET EDITFILE
The SET EDITFILE command lets you change the name of the work file that is created when you use the EDIT
command to edit the SQL statement in the buffer:
SET EDITF[ILE] edit_filename

< previous page page_417 next page >
< previous page page_418 next page >
Page 418
where:
SET EDITF[ILE]
Is the command, which may be abbreviated to SET EDITF.
edit_filename
Is the filename you want SQL*Plus to use when you issue an EDIT command. The default value is afiedt.buf. The
filename you specify may optionally include a path.
If you do not include an extension as part of the filename, the current value of the SUFFIX setting will be used as the
extension.
SET INSTANCE
The SET INSTANCE command allows you to specify a default database to connect to when you use the CONNECT
command without specifying a service name. You cannot issue this command while connected to a database; you must
disconnect first.
SET INSTANCE [service_name¦ LOCAL]
where:

SET INSTANCE
Is the command, which may not be abbreviated. Issuing the command SET INSTANCE with no parameters has the same
effect as SET INSTANCE LOCAL.
service_name
Is a Net8 (SQL*Net) service name.
LOCAL
Sets the default instance to be your local database. This is the default setting. In a Windows environment, the local
database is the one specified by the LOCAL registry setting.
The Show Command
The SHOW command allows you to look at the current state of your SQL*Plus environment. You can use it to display the
current value of any setting controlled by the SET command. SHOW may also be used to look at current page titles, page
footers, and so forth.
SHO[W] setting
ALL
BTI [TLE]
ERR[ORS] [{FUNCTION ¦ PROCEDURE ¦ PACKAGE ¦ PACKAGE BODY¦
TRIGGER ¦ TYPE ¦ TYPE BODY ¦ VIEW} [owner.] object_name]
LNO

< previous page page_418 next page >
< previous page page_419 next page >
Page 419
PARAMETERS [parameter_name]
PNO
REL[EASE]
REPF[OOTER]
REPH[EADER]
SGA
SPOO[L]
SQLCODE

TTI[TLE]
USER
where:
SHO[W]
Is the command, which may be abbreviated to SHO.
setting
Is any one of the settings you can set using the SET command.
ALL
Shows everything, except for errors and the SGA.
BTI[TLE]
Displays the current page footer.
ERR[ORS]
Displays an error listing for a stored object. The command SHOW ERRORS by itself causes the error listing for the
most recently created object to be displayed. You can get the error listing for a specific object by specifying the object
type (function, procedure, and so forth) and the object name.
FUNCTION ¦ PROCEDURE ¦ PACKAGE ¦ PACKAGE BODY ¦ TRIGGER ¦ TYPE ¦
TYPE BODY ¦ VIEW
Used with SHOW ERRORS to specify the object type of interest. This is only necessary if you are specifying the name
of the object.
[owner.]object_name
Used with SHOW ERRORS to name the object for which you want to display an error listing.
LNO
Displays the current line number.
PARAMETER[S] [parameter_name]
Displays the current value of one or more initialization parameters. Chapter 10 provides detailed examples of SHOW
PARAMETERS in use.
PNO
Displays the current page number.

< previous page page_419 next page >

< previous page page_420 next page >
Page 420
REL[EASE]
Displays the release number (version) of the Oracle database to which you are connected.
REPF[OOTER]
Displays the current report footer.
REPH[EADER]
Displays the current report header.
SGA
Displays information about the current state of the System Global Area. See Chapter 10 for more information about this
option.
SPOO[L]
Tells you whether or not output is currently being spooled to a file.
SQLCODE
Displays the SQL code returned by the most recent SQL statement.
TTI[TLE]
Displays the current page title.
USER
Displays the current username.
The following few examples demonstrate how the SHOW command may be used to display the value of one item, such
as a setting or a page title:
SQL> SHOW LINESIZE
linesize 80
SQL> SHOW USER
USER is JEFF
SQL> SHOW TTITLE
ttitle OFF and is the 1st few characters of the next SELECT statement
The ALL option may be used to display the value of all settings at once. Here is an example:
SQL> SHOW ALL
appinfo is ON and set to SQL*Plus

arraysize 15
autocommit OFF
autoprint OFF
autotrace OFF
shiftinout INVISIBLE
blockteminator . (hex 2e)
As you can see, when you use SHOW ALL, the settings are displayed in alphabetical order.

< previous page page_420 next page >
< previous page page_421 next page >
Page 421
The SHOW ERRORS command has more parameters than the other options, so it's a bit more complex. SHOW ERRORS is
used to display error listings for stored procedures, stored functions, packages, triggers, and other such objects. Typically, you
first issue a CREATE statement, and then, if errors are reported, you follow that with a SHOW ERRORS command. The
following example uses SHOW ERRORS to display an error listing for the most recent creation attempt:
SQL> CREATE OR REPLACE TRIGGER employee_set_key
2 BEFORE INSERT ON employee
3 FOR EACH ROW
4 BEGIN
5 :new.employee_id := employee_seq.nextval;
6 END;
7 /

Warning: Trigger created with compilation errors.

SQL> SHOW ERRORS
Errors for TRIGGER EMPLOYEE_SET_KEY:

LINE/COL


ERROR

2/3
PL/SQL: Statement ignored

2/3
PLS-00201: identifier EMPLOYEE_SEQ.NEXTVAL must be declared

SQL>
You can show errors for a specific object by telling SQL*Plus both the object type and the object name:
SQL> CREATE OR REPLACE PROCEDURE JEFF.DISABLE_TRIGGER AS
2 BEGIN
3 ALTER TABLE EMPLOYEE DISABLE TRIGGER EMPLOYEE_SET_KEY;
4 END;
5 /

Warning: Procedure created with compilation errors.

SQL> SHOW ERRORS PROCEDURE JEFF.DISABLE_TRIGGER
Errors for PROCEDURE JEFF.DISABLE_TRIGGER:

LINE/COL

ERROR

3/3
PLS-00103: Encountered the symbol ALTER when expecting one of the
following:

< previous page page_421 next page >

< previous page page_422 next page >
Page 422
begin declare exit for goto if loop mod null pragma raise
return select update while <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql commit <a single-quoted SQL string>
The error listings stick around even after you end the session in which you tried to create the object. You can come back
later, display the errors, and pick up where you left off. But when you do that, you must explicitly name the object you
are working with.

< previous page page_422 next page >

×