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