Run SQL in Linux Shell

Source: Internet
Author: User

Execute the SQL statement of the Oracle database in Shell

 
#### Function #### Description: Execute an SQL statement ### input parameters: {SQL statement} {database TNS} {database user name} {Database User Password} #### output parameters: SQL Execution result function exe_ SQL {SQL = $ 1oracle_sid = $ 2user_name = $ response = $ 4error_code = 'sqlplus-S-l/nolog <eofconnect $ user_pwd/$ user_pwd @ $ oracle_sidset termout off; set echo off; Set feedback off; Set heading off; Set pagesize 0; $ SQL; commit; quiteof 'echo "$ error_code" If [-z "$ error_code"]; thenreturn 0 else return 1fi}

Sid:

The database instance id, that is, the name of the database instance. In the control panel-management tools-service, open this file and you can see an oracleserviceXxxWhere "XXX" is

The name of your database instance, that is, Sid.

TNS:

The data connection string represents the connection of a Database. After you configure your data network connection, there will be such a string. This string can be found in your Oracle Installation root directory \ ora92 \ Network \ admin \ tnsnames. SQL. You can find this file in your Oracle installation directory,

Orac =
(Description =
(Address_list =
(Address = (Protocol = TCP) (host = CYL) (Port = 1521 ))
)
(CONNECT_DATA =
(Server = dedicated)
(SERVICE_NAME = d7i)
)
)
The above "Orac" is the TNS you want. You can copy and overwrite a TNS and direct the host to the IP address of your database server,
SERVICE_NAME = your database Sid

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.