解决执行脚本时爆“sqlplus: command not found”的问题

简介:

如题所示,在安装了oracle的Linux服务器上执行脚本时出现如题的错误:

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

问题分析:

情况一:使用root用户切换到oracle用户时使用了以下命令

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

这样切换用户导致从root用户切换到oracle用户时没有加载/home/oracle/.bash_profile文件,因此环境变量没有加载进来

正确命令应该是:

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

然后进行测试:

1
2
[oracle@hp-db ~]$  echo  $ORACLE_HOME
/home/oracle/app/oracle/product/11 .2.0 /dbhome_1
1
[oracle@hp-db ~]$ sqlplus  "/ as sysdba"

可以发现已经可以正常进入SQL命令模式了

情况二:/home/oracle/.bash_profile文件中的oracle环境变量设置得不太正确

如果是这个文件中的环境变量设置不对的话,只需要参考一个正确的配置文件根据实际情况修改即可,参考文件如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#Oracle Config
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=hp-db
export ORACLE_BASE=/home/oracle/app
export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=yoursid
export ORACLE_TERM=xterm
export ORACLE_UNQNAME=yourunqname
export PATH=/usr/sbin:$ORACLE_HOME/bin:$PATH
export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
export EMLOCALHOST=localhost.oracle
export NLS_DATE_FORMAT="YYYY-MM-DD  HH24:MI:SS"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

附:最上面的那个shell脚本getSysdate.sh是这样的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash
VALUE=`sqlplus -S  "/ as sysdba"  << !
set  heading off
set  feedback off
set  pagesize 0
set  verify off
set  echo  off
select  to_char(sysdate, 'yyyy-mm-dd' ) today from dual;
exit
!`
echo  $VALUE
if  [ -n  "$VALUE"  ];  then
echo  "The rows is $VALUE"
exit  0
else
echo  "There is no row"
fi

再次执行效果如下:

1
2
3
[oracle@hp-db  test ]$ . /getSysdate .sh
2016-08-19
The rows is 2016-08-19



本文转自 pangfc 51CTO博客,原文链接:http://blog.51cto.com/983836259/1861364,如需转载请自行联系原作者
相关文章
|
1月前
oralce check 命令
oralce check 命令
21 1
|
Shell Linux
Centos7:“Entering emergency mode. Exit the shell to continue”错误解决方法
想过很多朋友有遇到这种情况,就是正在远程使用centos7系统时,一旦让远程虚拟机或服务器断电或强制关机,那么再次重启时就会出现“Entering emergency mode. Exit the shell to continue.”的错误。
9949 0
Centos7:“Entering emergency mode. Exit the shell to continue”错误解决方法
|
10月前
|
Ubuntu 关系型数据库 MySQL
提示-bash: command not found的解决方法集锦
提示-bash: command not found的解决方法集锦
|
Shell
shell:使用command判断一个命令是否存在
shell:使用command判断一个命令是否存在
224 0
|
关系型数据库 PostgreSQL iOS开发
zsh: command not found: psql 解决方法
zsh: command not found: psql 解决方法
|
Linux Shell Windows
Shell - line 2: $‘\r‘: command not found
拷贝脚本提交后报错 line 2: $'\r': command not found,但是这是别的同学可以运行后发给我的,随后开始排查。安装 dos2unix 需要使用 yum。安装 yum 需要使用 brew。
395 0
Shell - line 2: $‘\r‘: command not found
|
数据安全/隐私保护
提示 you neet to root to perform this command 的解决办法
提示 you neet to root to perform this command 的解决办法
|
Shell
bash:govendor:command not found 如何解决?
bash:govendor:command not found 如何解决?
441 0
|
移动开发 Linux Shell
$‘\r‘: command not found的解决方法
在Linux系统中,运行Shell脚本,出现了如下错误: one-more.sh: line 1: $'\r': command not found 1 出现这样的错误,是因为Shell脚本在Windows系统编写时,每行结尾是\r\n,而在Linux系统中行每行结尾是\n,所以在Linux系统中运行脚本时,会认为\r是一个字符,导致运行错误。
1220 0