Oraclede的 SQL*PLus提供了一個命令行方式的解釋器,同時支持SQL和PL/SQL。SQL*Plus可以接受用戶輸入的語句,然後把語句發送給Oracle服務器,並顯示處理結果。
1.啓動SQL*Plus
爲了啓動SQL*Plus需要跟隨以下步驟:
1.1執行以下的其中一項
- 確認PATH環境變量包含了ORACLE_HOME/bin。
- 改變目錄爲ORACLE_HOME/bin。
1.2輸入命令
sqlplus /nolg
(注意:LINUX和UNIX操作系統對大小寫敏感)
2.SQL*Plus連接語句
提交SQL*Plus連接語句開始連接到Oracle實例,或在任何時刻重新連接到一個不同的用戶。連接語句的語法如下:
CONN[ECT] [username | /][@connect_identifier] [AS {SYSOPER | SYSDBA}]
當你輸入用戶名後,SQL*Plus會提示輸入密碼,你輸入的密碼是不會被顯示的。
下表描述了在CONNECT語句的語法成分。
語法成分 | 描述 |
/ |
調用連接請求的外部驗證,這種驗證類型不需要數據庫密碼。最常見的外部驗證結構是操作系統驗證,數據庫用戶身份驗證通過使用主機賬戶登錄到主機操作系統。也可以通過Oracle錢包或由網絡服務進行外部認證 |
AS {SYSOPER | SYSDBA | 指明數據庫用戶正在以SYSOPER或SYSDBA系統權限連接,只有某些預定義的用戶或者已經添加到密碼文件的用戶才能使用這些權限。 |
username |
一個有效的數據庫用戶名。數據庫通過在數據字典中查找匹配的用戶名驗證請求,並提示數據用戶密碼。 |
connect_identifier(1) |
一個Oracle Net連接標識符,用來遠程連接,確切語法取決於Oracle Net配置。如果省略,SQL*Plus嘗試連接到本地實例。 一個常見的連接標識符是OracleNet連接描述符(網絡地址和數據庫服務名)的別名,網絡服務名稱。網絡服務名稱通常是定義在本地tnsname.ora文件中,但也可以使用其他方法定義。 |
connect_identifier(2) |
作爲另外一個連接標識符,它可以使用簡單的連接語法。簡易連接提供了即裝即用TCP/IP連接到遠程數據庫,而無需在本地電腦上配置Oracle網絡服務。 連接的連接標識符的語法如下: host[:port][/service_name] 其中: host:遠程數據庫計算機的主機名或IP地址。 port:主機上Oracle網絡監聽器監聽數據庫連接的TCP端口。如果省略,默認是1521。 service_name:數據庫服務名,如果遠程主機上的Oracle網絡監聽器配置默認服務,則可以省略。如果沒有配置值默認服務,則必須要提供。每個數據庫通常提供的服務名稱等於全局數據庫名
|
3.EXAMPLES
3.1使用SYSDBA系統權限以操作系統驗證方式連接到數據庫
connect / as sysdba
3.2使用簡易連接標識符連接到遠程數據庫
connect [email protected]:1522/sales.mycompany.com
4.SQL*PLUS命令彙總
Command | Description |
---|---|
@ (at sign) |
Runs SQL*Plus statements in the specified script. The script can be called from the local file system or from a web server. |
@@ (double at sign) |
Runs a script. This command is similar to the @ (at sign) command It is useful for running nested scripts because it looks for the specified script in the same path as the calling script. |
/ (slash) |
Executes the SQL command or PL/SQL block. |
ACCEPT |
Reads a line of input and stores it in a given substitution variable. |
APPEND |
Adds specified text to the end of the current line in the buffer. |
ARCHIVE LOG |
Starts or stops the automatic archiving of online redo log files, manually (explicitly) archives specified redo log files, or displays information about redo log files. |
ATTRIBUTE |
Specifies display characteristics for a given attribute of an Object Type column, and lists the current display characteristics for a single attribute or all attributes. |
BREAK |
Specifies where and how formatting will change in a report, or lists the current break definition. |
BTITLE |
Places and formats a specified title at the bottom of each report page, or lists the current BTITLE definition. |
CHANGE |
Changes text on the current line in the buffer. |
CLEAR |
Resets or erases the current clause or setting for the specified option, such as BREAKS or COLUMNS. |
COLUMN |
Specifies display characteristics for a given column, or lists the current display characteristics for a single column or for all columns. |
COMPUTE |
Calculates and prints summary lines, using various standard computations, on subsets of selected rows, or lists all COMPUTE definitions. |
CONNECT |
Connects a given user to Oracle Database. |
COPY |
Copies results from a query to a table in the same or another database. |
DEFINE |
Specifies a substitution variable and assigns it a CHAR value, or lists the value and variable type of a single variable or all variables. |
DEL |
Deletes one more lines of the buffer. |
DESCRIBE |
Lists the column definitions for the specified table, view, or synonym or the specifications for the specified function procedure. |
DISCONNECT |
Commits pending changes to the database and logs the current user off Oracle Database, but does not exit SQL*Plus. |
EDIT |
Invokes an operating system text editor on the contents of the specified file or on the contents of the buffer. |
EXECUTE |
Executes a single PL/SQL statement. |
EXIT |
Terminates SQL*Plus and returns control to the operating system. |
GET |
Loads an operating system file into the buffer. |
HELP |
Accesses the SQL*Plus command-line help system. |
HOST |
Executes an operating system command without leaving SQL*Plus. |
INPUT |
Adds one or more new lines after the current line in the buffer. |
LIST |
Lists one or more lines of the buffer. |
PASSWORD |
Enables a password to be changed without echoing the password on an input device. |
PAUSE |
Displays the specified text, then waits for the user to press Return. |
|
Displays the current value of a bind variable. |
PROMPT |
Sends the specified message to the user's screen. |
EXIT |
Terminates SQL*Plus and returns control to the operating system QUIT is identical to EXIT. |
RECOVER |
Performs media recovery on one or more tablespaces, one or more datafiles, or the entire database. |
REMARK |
Begins a comment in a script. |
REPFOOTER |
Places and formats a specified report footer at the bottom of each report, or lists the current REPFOOTER definition. |
REPHEADER |
Places and formats a specified report header at the top of each report, or lists the current REPHEADER definition. |
RUN |
Lists and runs the SQL command or PL/SQL block currently stored in the SQL buffer. |
SAVE |
Saves the contents of the buffer in an operating system file (a script). |
SET |
Sets a system variable to alter the SQL*Plus environment for your current session. |
SHOW |
Shows the value of a SQL*Plus system variable or the current SQL*Plus environment. |
SHUTDOWN |
Shuts down a currently running Oracle Database instance. |
SPOOL |
Stores query results in an operating system file and, optionally, sends the file to a printer. |
START |
Runs the SQL statements in the specified script. The script can be called from a local file system or a web server in SQL*Plus command-line. |
STARTUP |
Starts an Oracle Database instance and optionally mounts and opens a database. |
STORE |
Saves attributes of the current SQL*Plus environment in an operating system script. |
TIMING |
Records timing data for an elapsed period of time, lists the current timer's title and timing data, or lists the number of active timers. |
TTITLE |
Places and formats a specified title at the top of each report page, or lists the current TTITLE definition. |
UNDEFINE |
Deletes one or more substitution variables that you defined either explicitly (with the DEFINE command) or implicitly (with an argument to the START command). |
VARIABLE |
Declares a bind variable that can be referenced in PL/SQL. |
WHENEVER OSERROR |
Exits SQL*Plus if an operating system command generates an error. |
WHENEVER SQLERROR |
Exits SQL*Plus if a SQL command or PL/SQL block generates an error. |
XQUERY |
Runs an XQuery 1.0 statement. |