Unix/Linux中shell调用sqlplus的方式
Unix/Linux下,shell脚本调用sqlplus的几种方式介绍:
一、最简单的shell调用sqlplus
#!/bin/bash
sqlplus -S /nolog > sqlplus.log <<EOF
conn scott/scott
select sysdate from dual;
quit
EOF
二、sqlplus返回执行结果给shell
方法一:
#!/bin/bash
biz_date=`sqlplus -S scott/scott <<EOF
set heading off
set pagesize 0;
set feedback off;
set verify off;
set echo off;
select sysdate from dual;
exit
EOF`
echo $biz_date
(注意:等号两侧不能有空格.)
[oracle@toughhou shell]$ vi sqlplus.sh
21-NOV-13
方法二:
注意sqlplus段使用 col .. new_value .. 定义了变量并带参数exit, 然后自动赋给了shell的$?
#!/bin/bash
sqlplus -S scott/scott <<EOF
set heading off
set pagesize 0;
set feedback off;
set verify off;
set echo off;
col biz_date new_value v_biz_date
select sysdate biz_date from dual;
exit v_biz_date
EOF
biz_date="$?"
[oracle@toughhou shell]$ vi sqlplus.sh
sqlplus.sh: line 11: warning: here-document at line 1 delimited by end-of-file (wanted `EOF')
21-NOV-13
这里出warning是因为EOF后面有空格。(注意:结尾出的EOF后面不能有任何字符)
去掉空格后结果如下:
[oracle@toughhou shell]$ vi sqlplus.sh
22-NOV-13
三、shell程序传递参数给sqlplus
sqlplus里可以直接使用, 赋变量的等号两侧不能有空格不能有空格.
接收到的变量不能加引号。“select sysdate from $tb;"不能写成"select sysdate from '$tb';"
#!/bin/bash
tb=dualsqlplus -S scott/scott <<EOF
set heading off
set pagesize 0;
set feedback off;
set verify off;
set echo off;
select sysdate from $tb;
exit
EOF
[oracle@toughhou shell]$ sh sqlplus.sh
22-NOV-13
四、为了安全要求每次执行shell都手工输入密码
#!/bin/bash
echo -n "Enter db password for scott: "
read pwdsqlplus -S scott/$pwd <<EOF
set heading off
set pagesize 0;
set feedback off;
set verify off;
set echo off;
select sysdate from dual;
exit
EOF
[oracle@toughhou shell]$ sh sqlplus.sh
Enter db password for scott: scott
22-NOV-13
五、为了安全从文件读取密码
对密码文件设置权限, 只有用户自己才能读写.
[oracle@toughhou shell]$ echo scott > scott.pwd
[oracle@toughhou shell]$ chmod 500 soctt.pwd
[oracle@toughhou shell]$ chmod 500 scott.pwd
[oracle@toughhou shell]$ ls -l scott.pwd
-r-x------ 1 oracle oinstall 6 Nov 22 00:17 scott.pwd
#!/bin/bash
pwd=`cat scott.pwd`sqlplus -S scott/$pwd <<EOF
set heading off
set pagesize 0;
set feedback off;
set verify off;
set echo off;
select sysdate from dual;
exit
EOF
Unix/Linux中shell调用sqlplus的方式的更多相关文章
- linux中shell变量$#,$@,$0,$1,$2的含义
linux中shell变量$#,$@,$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行 ...
- Linux中Shell
Linux中Shell Shell是什么 Shell是一个命令行解释器,为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序,可以用Shell来启动.挂起.停止.编写一些程序. S ...
- linux中Shell标准输出错误 >/dev/null 2>&1 分析【转】
Shell中可能经常能看到:>/dev/null 2>&1 eg:sudo kill -9 `ps -elf |grep -v grep|grep $1|awk '{print ...
- [转]unix/linux中的dup()系统调用
[转]unix/linux中的dup()系统调用 在linux纷繁复杂的内核代码中,sys_dup()的代码也许称得上是最简单的之一了,但是就是这么一个简单的系统调用,却成就了unix/linu ...
- linux中shell变量$#,$@,$0,$1,$2的含义解释
linux中shell变量$#,$@,$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行 ...
- ASP.net 中手工调用WS(POST方式)
ASP.net 中手工调用WS(POST方式)核心代码:string strUrl="http://localhost:21695/service1.asmx/getmythmod" ...
- linux中shell变量$#,$@,$0,$1,$2的含义解释
linux中shell变量$#,$@,$0,$1,$2的含义解释 linux中shell变量$#,$@,$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID ...
- Linux中shell变量$0,$?等含义
linux中shell变量$#,$@,$0,$1,$2的基本含义: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行 ...
- 【转】linux中shell变量$#,$@,$0,$1,$2的含义解释
原文网址:http://www.cnblogs.com/fhefh/archive/2011/04/15/2017613.html linux中shell变量$#,$@,$0,$1,$2的含义解释: ...
随机推荐
- Emacs安装auto-complete
分别下载各个el文件 auto-complete-mode 主源码库 https://github.com/auto-complete/auto-complete 把zip文件下载后,复制auto-c ...
- python(2)-字符串(2)
字符串格式化: 前面说过一种字符串格式化方法,来复习一下: >>> print('His name is %s', 'jeff') His name is %s jeff 其实格式化 ...
- Xcode磁盘空间大清理(转)
Xcode磁盘空间大清理 我的设备是Macbook Air 13’ Mid 2011,128G SSD.最近开始有些存储压力了,用Clean My Mac清理一部分旧文件后,决定对Xcode动手. 移 ...
- ENVI/IDL与ArcGIS集成开发的三种途径
转载:本文来自ENVI5.0-IDL8.2系列产品白皮书_201303.PDF(Esri中国官网可下载)中P7-P10 ENVI 是一个非常开放的平台,提供一个健全的函数库,几乎涵盖ENVI 平台大部 ...
- img与父元素的间隙解决
近来在做H5页面时,突然发现一个问题,使用一个div包裹一个img,在手机预览时,发现图片与div之间有间隙. 当时第一反应就是,是不是间距没有设置为0,于是预览了下代码: .active img { ...
- 【Knockout】四、绑定上下文
Binding context binding context是一个保存数据的对象,你可以在你的绑定中引用它.当应用绑定的时候,knockout自动创建和管理binding context的继承关系. ...
- React Native之ViewPagerAndroid跳转页面问题
前言: 网上目前react-native的教程较少,加上许多帖子还是用的ES5(2015年6月已发布ES6标准),有些细节很难找到答案,这里把遇到的问题做一个分享,让学习者尽量少踩坑. 出现问题: 1 ...
- ios中Raw文件系统常用文件夹
1.[/Applications] 常用软件的安装目录 2.[/Applications/Preferences.app/zh_CN.lproj] 软件Preferences.app的中文汉化文件存放 ...
- sql常识-SQL 通配符
在搜索数据库中的数据时,您可以使用 SQL 通配符. SQL 通配符 在搜索数据库中的数据时,SQL 通配符可以替代一个或多个字符. SQL 通配符必须与 LIKE 运算符一起使用. 在 SQL 中, ...
- 资源汇集:nginx教程从入门到精通
http://linux.cn/article-4279-1.html