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的含义解释: ...
随机推荐
- storyBoard中的Segue跳转
//———————————————--------------在不确定的Segue跳转----------------------------------- 多个按钮指向要跳转的视图 1.在一个恰 ...
- xcode笔记
1.Alt键的使用 2.设置捕捉所有意外断点:停在代码出错处 2015年07月27日09:52:12 3.搜索 command + F:在当前的文件中搜索 command + Shift ...
- customerized convert from field type to DB field's type
@LastModifiedDate @Convert(converter = LocalDateTime2TimestampConverter.class) @Slf4j public class L ...
- C语言预处理操作符
在看<深入剖析Nginx>时看见一个非常少见的C语言知识点:预处理操作符. #define conn(x,y) x##y //将子串x和y连接形成新的串 #define tochar(x) ...
- 如何用C表示排列组合?
问题来自<Linux C一站式编程>,是个挺有意思的题目. 2.定义一个数组,编程打印它的全排列.比如定义: #define N 3 int a[N] = { 1, 2, 3 }; 则运行 ...
- 设计模式——java
设计模式:一个程序员对设计模式的理解:“不懂”为什么要把很简单的东西搞得那么复杂.后来随着软件开发经验的增加才开始明白我所看到的“复杂”恰恰就是设计模式的精髓所在,我所理解的“简单”就是一把钥匙开一把 ...
- 【已解决】BeautifulSoup已经获得了Unicode的Soup但是print出来却是乱码
[问题] 某人遇到的问题: 关于BeautifulSoup抓取表格及SAE数据库导入的问题(跪求大神帮忙) 简单说就是: 用如下代码: ? 1 2 3 4 5 6 7 import re,urllib ...
- Android Device Orientation
最近在处理相机拍照的方向问题,在Android Device的Orientation问题上有了些疑问,就顺便写个Demo了解下Android Device Orientation究竟是怎么个判断. A ...
- Asp.Net运行原理(=)
浏览器与服务器之间的通信. 一般浏览器与服务器之间的底层是通过socket建立连接的. 当浏览器与服务器之间建立了socket连接之后,服务器就开始监听. 当浏览器与服务器之间建立了相互兼容的协议之后 ...
- RNN-theano代码解析
import theano import numpy import os import pdb from theano import tensor as T from collections impo ...