About SQL*Plus SQL*Plus is the primary command-line interface to your Oracle database. You use SQL*Plus to start up and shut down the database, set da ...
About SQL*Plus
SQL*Plus is the primary command-line interface to your Oracle database. You use SQL*Plus to start up and shut down the database, set database initialization parameters, create and manage users, create and alter database objects (such as tables and indexes), insert and update data, run SQL queries, and more.
Before you can submit SQL statements and commands, you must connect to the database. With SQL*Plus, you can connect locally or remotely. Connecting locally means connecting to an Oracle database running on the same computer on which you are running SQL*Plus. Connecting remotely means connecting over a network to an Oracle database that is running on a remote computer. Such a database is referred to as a remote database. The SQL*Plus executable on the local computer is provided by a full Oracle Database installation, an Oracle Client installation, or an Instant Client installation.
See Also:
Connecting to the Database with SQL*Plus
Oracle Database includes the following components:
-
The Oracle Database instance, which is a collection of processes and memory
-
A set of disk files that contain user data and system data
When you connect with SQL*Plus, you are connecting to the Oracle instance. Each instance has an instance ID, also known as a system ID (SID). Because there can be multiple Oracle instances on a host computer, each with its own set of data files, you must identify the instance to which you want to connect. For a local connection, you identify the instance by setting operating system environment variables. For a remote connection, you identify the instance by specifying a network address and a database service name. For both local and remote connections, you must set environment variables to help the operating system find the SQL*Plus executable and to provide the executable with a path to its support files and scripts. To connect to an Oracle instance with SQL*Plus, therefore, you must complete the following steps:
Step 1: Open a Command Window
Step 2: Set Operating System Environment Variables
根據你的平臺,您可能必須在啟動SQL * Plus之前設置環境變數,或至少驗證設置是否正確
例如,在大多數平臺上,必須設置ORACLE_SID和ORACLE_HOME。另外,建議將PATH環境變數設置為包含ORACLE_HOME / bin目錄。有些平臺可能需要額外的環境變數:
- 在UNIX和Linux平臺上,您必須通過輸入操作系統命令來設置環境變數。
- 在Windows平臺上,Oracle Universal Installer(OUI)會自動將值分配給Windows註冊表中的ORACLE_HOME和ORACLE_SID。
對於所有平臺,當在具有不同Oracle主目錄的實例之間切換時,必須更改ORACLE_HOME環境變數。如果多個實例共用同一個Oracle主目錄,則在切換實例時必須僅更改ORACLE_SID。
1 setenv ORACLE_SID orcl 2 setenv ORACLE_HOME /u01/app/oracle/product/11.2.0/db_1 3 setenv LD_LIBRARY_PATH $ORACLE_HOME/lib:/usr/lib:/usr/dt/lib:/usr/openwin/lib:/usr/ccs/libExample 1-1 Setting Environment Variables in UNIX (C Shell)
1 SET ORACLE_SID=orawin2
Example 1-2 Setting Environment Variables in Windows
Example 1-2假定在註冊表中設置了ORACLE_HOME和ORACLE_SID,但你希望覆蓋ORACLE_SID的註冊表值以連接到其他實例。 在Windows上,您在命令提示符視窗中設置的環境變數值會覆蓋註冊表中的值。
Step 3: Start SQL*Plus
1 sqlplus /nolog
Step 4: Submit the SQL*Plus CONNECT Statement
the CONNECT
statement is as follows:
CONN[ECT] [logon] [AS {SYSOPER | SYSDBA}]
The syntax of logon
is as follows:
{username | /}[@connect_identifier] [edition={edition_name | DATABASE_DEFAULT}]
下表介紹了CONNECT語句的語法:
/ |
調用連接請求的外部認證。這種類型的認證中不使用資料庫密碼。 最常見的外部身份驗證形式是操作系統身份驗證,其中資料庫用戶通過使用 特定主機用戶帳戶登錄到主機操作系統進行身份驗證。外部認證也可以通過 Oracle wallet或network service來進行。 |
AS {SYSOPER | SYSDBA} |
表示資料庫用戶正在使用SYSOPER或SYSDBA系統特權進行連接。只有 某些預定義的管理用戶或已添加到密碼文件的用戶才可以使用這些許可權進行連接。 參閱:Administrative Privileges Using Operating System Authentication |
username |
一個有效的資料庫用戶名。資料庫通過將用戶名與數據字典匹配並提示輸入用戶密碼 來驗證連接請求 |
connect_identifier (1) | 一個Oracle Net連接標識符,用於遠程連接。確切的語法取決於Oracle Net配置。
如果省略,SQL * Plus將嘗試連接到本地實例。 常用連接標識符是網路服務名稱。 |
connect_identifier (2) |
作為替代,連接標識符可以使用簡單連接語法。輕鬆連接為遠程資料庫提供開箱即用 的TCP / IP連接,而無需在客戶端(本地)電腦上配置Oracle Net Services。 連 接標識符的簡單連接語法如下(必須包含括起來的雙引號): host[:port][/service_name][:server][/instance_name]
則預設類型的伺服器由偵聽器選擇:共用伺服器(如果已配置),否則為專用 伺服器 |
|
指定新資料庫會話啟動的版本。如果指定一個版本,它必須存在,並且您必須具有USE 特權。如果未指定此子句,則會話將使用資料庫預設版本 |
參考資料
https://docs.oracle.com/cd/E11882_01/server.112/e25494/dba.htm#ADMIN12472