SQLPLUS The SQLPLUS command is used from the operating system prompt to start SQL*Plus, and is discussed in Chapter 2, Interacting with SQL*Plus.. At Sign @ The at sign is used to execut
Trang 1A
SQL*Plus Command Reference
SQLPLUS
The SQLPLUS command is used from the operating system prompt to start SQL*Plus, and is discussed in Chapter 2,
Interacting with SQL*Plus.
SQLPLUS [[-SILENT] [username[ /password][@connect] ¦/¦/NOLOG]
[@scriptfile [arg1 arg2 arg3 ]]]¦-¦-?
where:
SQLPLUS
Is the command to use when invoking SQL*Plus On a Unix system this will be lowercase sqlplus From Windows or
MS-DOS, you may need to use PLUS80 or PLUS80W Beginning with release 8.1, the command under Windows, or
from a DOS prompt, will always be SQLPLUS.
-S[ILENT]
Tells SQL*Plus to run in silent mode No startup messages, such as the copyright message, will be displayed No
command prompt will be displayed, and no commands will be echoed to the screen This is useful if you are invoking SQL*Plus from within some other program, and you want to do it transparently Normally you would use this option in conjunction with invoking a script file
username
Is your database username
password
Is your database password
Trang 2
connect
Is the connect string, or host string, telling SQL*Plus the database to which you want to connect
/ Use a forward slash instead of your username, password, and connect string when you want to connect to a local
database using operating-system authentication
/NOLOG
Tells SQL*Plus not to connect you to any database at all You will get a SQL> prompt, but you must issue a
CONNECT command before you can do much else
scriptfile
Is the name of a SQL*Plus script file you want to run SQL*Plus will start up, execute the file, then exit
arg1 arg2 arg3
Are optional command-line arguments to pass to your script You can have as many as your script requires Arguments are separated from each other by at least one space
- Causes SQL*Plus to display a short summary of the SQLPLUS syntax
-? Causes SQL*Plus to display version and copyright information
Comment Delimiters (/* */)
The /* and */ delimiters may be used to set off a comment in SQL*Plus Comments entered this way may span multiple lines If you use /**/ in a script file, the comments will be displayed on the screen when the script is executed Chapter
4, Writing SQL*Plus Scripts, talks about the different ways to enter comments in SQL*Plus.
/*
comment_text
comment_text
comment_text
*/
where:
/* Marks the beginning of the comment
comment_text
Is the text making up the comment
*/ Marks the end of the comment
Trang 3
Double Hyphen (- -)
The double hyphen may be used to place a single-line comment in a SQL*Plus script, and is described in Chapter 4 The double hyphen works the same way as REMARK, except that it may also be used in SQL statements and PL/SQL blocks When used in a SQL statement or PL/SQL block, the double-hyphen may also be used to add trailing comments
to a line The syntax looks like this:
comment_text
where:
Is a double hyphen, and tells SQL*Plus that the line in question is a comment line
comment_text
Is your comment
At Sign (@)
The at sign is used to execute a SQL*Plus script file A script file is simply a text file containing SQL*Plus commands The commands appear in the file just as you would enter them from the keyboard See Chapter 2 for a an introduction to this command Also see the @@ and START commands
@script_file [argument ]
where:
@ Is the command to execute a script file
script_file
Is the name of the file you want to execute, which may include the path and extension The default extension is SQL If you do not specify a path, SQL*Plus will look for the file first in the current working directory, then it will search each
directory listed in the SQLPATH environment variable See Chapter 10, Administration with SQL*Plus, for information
about customizing the search path
argument
Is an argument you wish to pass to the script You may pass as many arguments as you like Arguments must be
separated from each other by at least one space Arguments may be enclosed in quotes, and should be if they contain spaces Either single or double quotes may be used, at your discretion Your script may reference the first argument as
&1, the second as &2, and so forth
Trang 4
Double At Sign (@@)
The double at sign is used within a script file to execute another script file contained in the same directory as the first This is very convenient if you have two scripts, one that calls the other Use the @@ command in the first script file to call the second Then put both files in the same directory Now, regardless of whether or not that directory is in the search path, SQL*Plus will find the second file whenever the first calls for it If used interactively, @@ functions
exactly the same as @
A script file is simply a text file containing SQL*Plus commands The commands appear in the file just as you would enter them from the keyboard See Chapter 2 for an introduction to this command Also see the @ and START
commands
@@script_file [argument ]
where:
@@ Is the command to execute a script file
script_file
Is the name of the file you want to execute, and may include the path and the extension The default extension is SQL The default path is the one pointing to the directory where the calling script is stored
argument
Is an argument you wish to pass to the script You may pass as many arguments as you like Arguments must be
separated from each other by at least one space Arguments may be enclosed in quotes, and should be if they contain spaces Either single or double quotes may be used, at your discretion Your script may reference the first argument as
&1, the second as &2, and so forth
Forward Slash (/)
A forward slash is used to execute the SQL statement or PL/SQL block that is currently in the buffer See Chapter 2 for more information, and for examples
/
where:
/ Causes SQL*Plus to execute the statement in the buffer The buffer is not changed by this command, and / can be used repeatedly to execute the same statement again and again
Trang 5
The ACCEPT command is used to get input from a user It causes SQL*Plus to display a prompt and wait for the user
to type something in response You can read about ACCEPT in Chapter 4 and in Chapter 7, Advanced Scripting.
ACC[EPT] user_variable [NUM[BER] ¦ CHAR ¦ DATE]
[FOR[MAT] fomat_specification]
[DEF[AULT] default_value]
[PROMPT prompt_text¦NOPR[OMPT] ]
[HIDE]
where:
ACC[EPT]
Tells SQL*Plus you want to prompt the user for a value and that you want the value stored in the specified user
variable The command may be abbreviated to ACC
user_variable
Is the variable you want to define Do not include leading ampersands If your script uses &table_name for a
substitution variable, you should use table_ name here
NUM[BER] \ CHAR \DATE
Is the type of data you are after The default is CHAR, which allows the user to type in anything as a response Use NUMBER to force the user to enter a number, and DATE when you want a date
FOR[MAT] format_specification
Is a format specification, which may optionally be enclosed in quotes ACCEPT will reject any input that does not conform to the specification An error message will be displayed and the prompt reissued Specifying a format makes the most sense when dealing with numeric and date data, and SQL*Plus is actually somewhat loose in enforcing the format Chapter 7 delves into this aspect of the ACCEPT command in detail Format elements are described in
Appendix B, SQL*Plus Format Elements.
DEF[AULT] default_value
Specifies a default value to assign to the variable This is used if the user bypasses the prompt by pressing ENTER without actually entering a response The default value should usually be enclosed within single quotes
PROMPT prompt_text
This is the prompt text displayed to the user before waiting for input
NOPR[OMPT]
Indicates that you do not want the user to see a visible prompt
Trang 6
HIDE
Causes SQL*Plus not to echo the user's response back to the display This is useful if you are prompting for a password
The syntax for the ACCEPT command has evolved significantly with the past few releases of SQL*Plus The syntax shown here is valid for version 8.1 Not all of the clauses are available when using prior versions Be sensitive to this and check your documentation if you are writing scripts that need to work under earlier versions of SQL*Plus
APPEND
Append is an editing command that lets you add text onto the end of the current line in the SQL buffer:
A[PPEND] text
where:
A[PPEND]
Is the command, which may be abbreviated to A
text
Is the text you want appended to the current line
APPEND, and all other editing commands, are described in Chapter 2
ARCHIVE LOG
The ARCHIVE LOG command is used to control, or display information about, archive logging It's discussed in
Chapter 10 and may be used to start archiving, stop archiving, manually archive one or more log files, or display
information about the current archive log state You must be connected as SYSDBA, SYSOPER, or INTERNAL in order to use this command
ARCHIEVE LOG {LIST
¦STOP
¦START [TO destination]
¦NEXT [TO destination]
¦ALL [TO destination]
¦log_sequence_number [TO destination]}
where:
ARCHIVE LOG
Is the command
Trang 7
LIST
Causes SQL*Plus to display information about the current state of archiving This includes the current destination, an indication of whether or not automatic archiving is enabled (the ARCH process), the oldest online log sequence number, the sequence number of the next log to be archived, and the current log sequence number
STOP
Stops logs files from being automatically archived You must manually archive redo log files as they fill; otherwise, you run the risk of the instance suspending operation because the log files have run out of space
START
Turns on automatic archiving of redo log files
NEXT
Manually archives the next log file group in the sequence, provided that it is filled Use ARCHIVE LOG LIST to see the sequence number of this file
ALL
Manually archives all log file groups that have been filled, but not previously archived
log_sequence_number
Manually archives a specific log file group, provided that group is still online Use ARCHIVE LOG LIST to find the sequence number of the oldest remaining log file group
destination
Specifies a destination for archived log files If used with ARCHIVE LOG START, this becomes the destination for all log files as they are archived If used with NEXT, ALL, or a specific sequence number, this becomes the destination for files archived by that one command If you do not specify a destination when using ARCHIVE LOG START, the value from the LOG_ARCHIVE_DEST initialization parameter is used
ATTRIBUTE
The ATTRIBUTE command is used to format attributes of an Oracle8 object type It functions like the COLUMN command, but with fewer parameters Chapter 4 talks about this command
ATTRIBUTE [object_type.attribute¦attribute_alias
[ALI[AS] alias¦
CLE[AR] ¦
FOR[MAT] format_spec¦
LIKE source_attribute¦
ON¦
OFF ]]
Trang 8
ATTRIBUTE
Is the command Issuing the ATTRIBUTE command with no parameters gets you a list of all current attribute settings
object_type
Is the name of an Oracle8 object type
attribute
Is the name of an attribute of the specified object type, and is the attribute you are formatting If you stop here and don't supply any other parameters, the current display settings for this attribute are shown
ALI[AS]alias
May be abbreviated ALI.ALIAS allows you to specify an alternate name for this attribute that is meaningful to
SQL*Plus
alias
Is an alternate name for the attribute that may be used in other ATTRIBUTE commands, in place of having to spell out the full object type and attribute name again
CLE[AR]
May be abbreviated to CLE CLEAR erases any format settings for the attribute in question This puts things back the way they were before any ATTRIBUTE commands were issued for the attribute
FOR[MAT]
May be abbreviated to FOR, and allows you to control how the data for the attribute is displayed For text fields, the format controls the maximum display length For numeric fields, you can control the width, placement of commas, placement of the dollar sign, and so on
fomat_spec
Is a string that specifies the display format for the attribute Appendix B describes the format specification elements that may be used with the ATTRIBUTE command
LIKE
Causes the attribute to be defined with the same format attributes as another attribute
source_column
Is the name of the source attribute used with the LIKE parameter This may be either an alias or a complete attribute reference using the standard dot notation
Trang 9
ON
Causes SQL*Plus to print the attribute using the format you have specified This is the default behavior You don't need
to use ON unless you have previously used OFF
OFF
Disables the format settings for the attribute SQL*Plus acts as if you had never issued any ATTRIBUTE commands for the attribute in question
When used with text attributes, formats such as A10 specify a maximum length to be displayed Longer values are truncated to match the length specified, and shorter values are left alone
BREAK
The BREAK command is used to define page breaks and line breaks based on changing column values in a report It controls whether or not duplicate values print in a column, and it controls the printing of computed values such as totals
and subtotals Chapter 3, Generating Reports with SQL*Plus, demonstrates the use of this command.
The BREAK command looks like this:
BRE[AK] [ON {column_name¦ROW¦REPORT)
[SKI[p] {lines_to_skip¦PAGE}¦
NODUP[LICATES]¦
DUP[LICATES] ] ]
where:
BRE[AK]
May be abbreviated BRE Issuing the BREAK command with no parameters causes SQL*Plus to display the current break setting
column_name
Specifies a report column to watch When the value in the column changes, SQL*Plus skips lines or pages as specified SQL*Plus also inhibits repeating, or duplicate, values from printing more than once unless the DUPLICATES keyword
is used
ROW
Causes SQL*Plus to break on each row You could doublespace a report by using BREAK ON ROW SKIP 1
REPORT
Specifies a report-level, break, and is used to cause SQL*Plus to print grand totals at the end of the report SKIP PAGE will be ignored if it is specified as a
Trang 10
port break action, but, strangely enough, the other form of the SKIP paprameter will work You can skip lines on a report break
SKI[P] lines_to_skip
Tells SQL*Plus to skip the specified number of lines when a break occurs SKIP may be abbreviated to SKI
SKI[P]PAGE
Tells SQL*Plus to advance to a new page when a break occurs
NODUP[LICATES]
Tells SQL*Plus to print a column's value only when it changes By default, whenever you put a break on a column, you get this behavior May be abbreviated NODUP
DUP[LICATES]
Forces SQL*Plus to print a column's value in every line on the report, regardless of whether or not the value is the same
as that printed for the previous record May be abbreviated as DUP
BTITLE
Use the BTITLE command to define page footers for a report Chapter 3 discusses BTITLE and has several examples Also see the TITTLE command BTITLE and TTITLE work the same way
BTI[TLE] [[OFF¦ON]¦
[COL x¦
S[KIP] x¦
TAB x¦
LE[FT]¦
CE[NTER]¦
R[IGHT]¦
BOLD ¦
FOR[MAT] format_spec¦
text¦
variable ]
where:
BTI[TLE]
May be abbreviated BTI Issuing the BTITLE command with no parameters causes SQL*Plus to display the current bottom title setting
OFF
Turns the page footer off, but does not erase its definition You can turn it back on again with ON