使用SQL*Plus鏈接數據庫

About SQL*Plussql


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:網絡

SQL*Plus User's Guide and Referenceoracle

 

Connecting to the Database with SQL*Plusapp


Oracle Database includes the following components:ide

  • The Oracle Database instance, which is a collection of processes and memoryui

  • A set of disk files that contain user data and system dataspa

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/lib
Example 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來進行。

參閱:Oracle Database Security Guide

AS {SYSOPER | SYSDBA} 

表示數據庫用戶正在使用SYSOPER或SYSDBA系統特權進行鏈接。只有

某些預約義的管理用戶或已添加到密碼文件的用戶纔可使用這些權限進行鏈接。

參閱:Administrative Privileges    Using Operating System Authentication

username  

一個有效的數據庫用戶名。數據庫經過將用戶名與數據字典匹配並提示輸入用戶密碼

來驗證鏈接請求

connect_identifier (1)  一個Oracle Net鏈接標識符,用於遠程鏈接。確切的語法取決於Oracle Net配置。

若是省略,SQL * Plus將嘗試鏈接到本地實例。 經常使用鏈接標識符是網絡服務名稱。
這是Oracle Net鏈接描述符(網絡地址和數據庫服務名稱)的別名。別名一般在本
地計算機上的tnsnames.ora文件中解析,但能夠用其餘方式解析

connect_identifier (2)

 做爲替代,鏈接標識符可使用簡單鏈接語法。輕鬆鏈接爲遠程數據庫提供開箱即用

的TCP / IP鏈接,而無需在客戶端(本地)計算機上配置Oracle Net Services。 連

接標識符的簡單鏈接語法以下(必須包含括起來的雙引號):

host[:port][/service_name][:server][/instance_name]

 

  • server是服務處理程序的類型。可接受的值是專用,共享和合並的。若是省略,

          則默認類型的服務器由偵聽器選擇:共享服務器(若是已配置),不然爲專用

          服務器

參閱:Oracle Database Net Services Administrator's Guide

edition={edition_name|DATABASE_DEFAULT}

 指定新數據庫會話啓動的版本。若是指定一個版本,它必須存在,而且您必須具備USE

特權。若是未指定此子句,則會話將使用數據庫默認版本

參閱:Oracle Database Advanced Application Developer's Guide

 

參考資料

https://docs.oracle.com/cd/E11882_01/server.112/e25494/dba.htm#ADMIN12472

相關文章
相關標籤/搜索