How to connect to oracle database through sqlplus

        This article introduces how to connect to the oracle database through sqlplus. If you use SQL Developer to connect to the database server, you need to install the Oracle client locally. The Oracle client installation package is relatively large, and the installation and configuration are also relatively cumbersome. It is recommended to install and use Oracle's Instant Client. Instant Client is a lightweight database client released by Oracle. Compared with the Oracle client of several hundred MB, this Instant Client is only tens of MB in size and takes up very little space.

1. Download Instant Client Base and sqlplus

        Visit the official address https://www.oracle.com/database/technologies/instant-client/downloads.html and select the appropriate version. This time, taking window as an example, select the 64-bit version.

 

        Enter the download page and select the latest version V21.10.0.0.0. Users can also choose the version that suits them according to their actual needs. Click the + on the right to display the download list.

Choose to download the basic package and sqlplus tool package of Instant Client respectively.

 

 2. Merge downloaded files

        Unzip the base package and sqlplus tool package downloaded in the previous step to the same directory. For example, create a new Oracle folder and extract all the files to this directory. An instantclient_21_10 folder will be generated under the oracle folder, and the files of the two installation packages will be placed in this folder.

3. Environment variable configuration 

  • Add the folder path X:\Oracle\instantclient_11_2 from the previous step to the system variable PATH.
  • Add environment variables:

        NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252 server-side character set

        TNS_ADMIN=X:\Oracle\instantclient_11_2 specifies the location of tnsnames.ora

4. Configure the tnsnames.ora file

        Add the tnsnames.ora file under the folder X:\Oracle\instantclient_11_2 and add the following configuration, where orcl is the database instance, 192.168.0.102 is the oracle database server IP address, and the default port is 1521.

orcl =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.102)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl.being.com)
    )
  )

 5. Use sqlplus to test the connection

         Open the cmd command line tool and execute the command sqlplus username/password@orcl to connect to the Oracle database.

sqlplus username/password@orcl

        You can also execute sqlplus username/[email protected]:1521/orcl to connect to the oracle database.

sqlplus username/[email protected]:1521/orcl

New Era Migrant Workers

Guess you like

Origin blog.csdn.net/sg_knight/article/details/132038161