Get the App
SLTechnology News&Howtos  ›  Database  › 

Solve the problem of exploding "sqlplus: command not found" when executing script

Shulou Source: shulou.com Published: 2022-06-01 10:36:23 10月06日 Update

As shown in the question, an error like this occurred while executing the script on the Linux server where oracle is installed:

[oracle@hp-db test] $. / getSysdate.sh./getSysdate.sh: line 10: sqlplus: command not found

Problem analysis:

Case 1: the following command is used when using root users to switch to oracle users

[root@hp-db test] # su oracle

This switching of users causes the / home/oracle/.bash_profile file not to be loaded when switching from root users to oracle users, so the environment variables are not loaded

The correct command should be:

[root@hp-db test] # su-oracle

Then test it:

[oracle@hp-db ~] $echo $ORACLE_HOME/home/oracle/app/oracle/product/11.2.0/dbhome_1 [oracle@hp-db ~] $sqlplus "/ as sysdba"

You can find that you can enter the SQL command mode normally.

Case 2: the oracle environment variable in the / home/oracle/.bash_profile file is not set correctly

If the environment variable in this file is set incorrectly, you only need to refer to a correct configuration file to modify it according to the actual situation. The reference file is as follows:

# Oracle Configexport TMP=/tmpexport TMPDIR=$TMPexport ORACLE_HOSTNAME=hp-dbexport ORACLE_BASE=/home/oracle/appexport ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1export ORACLE_SID=yoursidexport ORACLE_TERM=xtermexport ORACLE_UNQNAME=yourunqnameexport PATH=/usr/sbin:$ORACLE_HOME/bin:$PATHexport NLS_LANG= "AMERICAN_AMERICA.AL32UTF8" export EMLOCALHOST=localhost.oracleexport NLS_DATE_FORMAT= "YYYY-MM-DD HH24:MI:SS" export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/libexport CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

PS: the top shell script getSysdate.sh looks like this:

#! / bin/bashVALUE= `sqlplus-S "/ as sysdba"

Tags: File user variable command situation environment switch script reference problem wrong again actual effect server mode error face time out analysis Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MariaDB Huawei OPPO Reno Redmi