shell 调用 sqlplus 各种情况示例
来源:互联网 发布:国际数据分析师认证 编辑:程序博客网 时间:2024/04/27 19:51
shell 调用 sqlplus 各种情况示例
测试平台:RHEL4.5
一、最简单的shell里调用sqlplus.
$ vi test1.sh
#!/bin/bash
sqlplus -S /nolog > result.log <<EOF
set heading off feedback off pagesize 0 verify off echo off
conn u_test/iamwangnc
select * from tab;
exit
EOF
$ chmod +x test1.sh
$ ./test1.sh
二、把sqlplus执行结果传递给shell方法一
注意sqlplus段使用老板键`了, 赋变量的等号两侧不能有空格.
$ vi test2.sh
#!/bin/bash
VALUE=`sqlplus -S /nolog <<EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 4
conn u_test/iamwangnc
select count(*) from tab;
exit
EOF`
if [ "$VALUE" -gt 0 ]; then
echo "The number of rows is $VALUE."
exit 0
else
echo "There is no row in the table."
fi
$ chmod +x test2.sh
$ ./test2.sh
三、把sqlplus执行结果传递给shell方法二
注意sqlplus段使用 col .. new_value .. 定义了变量并带参数exit, 然后自动赋给了shell的$?
$ vi test3.sh
#!/bin/bash
sqlplus -S /nolog > result.log <<EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 4
conn u_test/iamwangnc
col coun new_value v_coun
select count(*) coun from tab;
exit v_coun
EOF
VALUE="$?"
echo "The number of rows is $VALUE."
$ chmod +x test3.sh
$ ./test3.sh
四、把shell程序参数传递给sqlplus
$1表示第一个参数, sqlplus里可以直接使用, 赋变量的等号两侧不能有空格不能有空格.
$ vi test4.sh
#!/bin/bash
NAME="$1"
sqlplus -S u_test/iamwangnc <<EOF
select * from tab where tname = upper('$NAME');
exit
EOF
$ chmod +x test4.sh
$ ./test4.sh ttt
五、为了安全要求每次执行shell都手工输入密码
$ vi test5.sh
#!/bin/bash
echo -n "Enter password for u_test:"
read PASSWD
sqlplus -S /nolog <<EOF
conn u_test/$PASSWD
select * from tab;
exit
EOF
$ chmod +x test5.sh
$ ./test5.sh
六、为了安全从文件读取密码
对密码文件设置权限, 只有用户自己才能读写.
$ echo 'iamwangnc' > u_test.txt
$ chmod g-rwx,o-rwx u_test.txt
$ vi test6.sh
#!/bin/bash
PASSWD=`cat u_test.txt`
sqlplus -S /nolog <<EOF
conn u_test/$PASSWD
select * from tab;
exit
EOF
$ chmod +x test6.sh
$ ./test6.sh
一、最简单的shell里调用sqlplus.
$ vi test1.sh
#!/bin/bash
sqlplus -S /nolog > result.log <<EOF
set heading off feedback off pagesize 0 verify off echo off
conn u_test/iamwangnc
select * from tab;
exit
EOF
$ chmod +x test1.sh
$ ./test1.sh
二、把sqlplus执行结果传递给shell方法一
注意sqlplus段使用老板键`了, 赋变量的等号两侧不能有空格.
$ vi test2.sh
#!/bin/bash
VALUE=`sqlplus -S /nolog <<EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 4
conn u_test/iamwangnc
select count(*) from tab;
exit
EOF`
if [ "$VALUE" -gt 0 ]; then
echo "The number of rows is $VALUE."
exit 0
else
echo "There is no row in the table."
fi
$ chmod +x test2.sh
$ ./test2.sh
三、把sqlplus执行结果传递给shell方法二
注意sqlplus段使用 col .. new_value .. 定义了变量并带参数exit, 然后自动赋给了shell的$?
$ vi test3.sh
#!/bin/bash
sqlplus -S /nolog > result.log <<EOF
set heading off feedback off pagesize 0 verify off echo off numwidth 4
conn u_test/iamwangnc
col coun new_value v_coun
select count(*) coun from tab;
exit v_coun
EOF
VALUE="$?"
echo "The number of rows is $VALUE."
$ chmod +x test3.sh
$ ./test3.sh
四、把shell程序参数传递给sqlplus
$1表示第一个参数, sqlplus里可以直接使用, 赋变量的等号两侧不能有空格不能有空格.
$ vi test4.sh
#!/bin/bash
NAME="$1"
sqlplus -S u_test/iamwangnc <<EOF
select * from tab where tname = upper('$NAME');
exit
EOF
$ chmod +x test4.sh
$ ./test4.sh ttt
五、为了安全要求每次执行shell都手工输入密码
$ vi test5.sh
#!/bin/bash
echo -n "Enter password for u_test:"
read PASSWD
sqlplus -S /nolog <<EOF
conn u_test/$PASSWD
select * from tab;
exit
EOF
$ chmod +x test5.sh
$ ./test5.sh
六、为了安全从文件读取密码
对密码文件设置权限, 只有用户自己才能读写.
$ echo 'iamwangnc' > u_test.txt
$ chmod g-rwx,o-rwx u_test.txt
$ vi test6.sh
#!/bin/bash
PASSWD=`cat u_test.txt`
sqlplus -S /nolog <<EOF
conn u_test/$PASSWD
select * from tab;
exit
EOF
$ chmod +x test6.sh
$ ./test6.sh
0 0
- shell 调用 sqlplus 各种情况示例
- shell 调用 sqlplus 各种情况示例
- shell 调用 sqlplus 各种情况示例
- shell 调用 sqlplus 各种情况示例
- shell 调用 sqlplus 各种情况示例
- shell调用sqlplus各种实例
- shell调用各种sqlplus用法
- shell调用各种sqlplus用法
- shell调用sqlplus
- Shell-sqlplus循环调用
- shell调用sqlplus例子
- shell中调用sqlplus
- shell调用sqlplus查询oracle
- shell调用sqlplus查询oracle
- Oracle Script-Shell调用SQLplus输出结果
- 在shell脚本中调用sqlplus
- 在shell脚本中调用sqlplus
- 调用layoutSubviews各种情况分析
- .Net下的SQLite操作
- Java导出Excel表格
- Dismiss对话框的时候,Activity已经不再存在
- C++关注备注部分知识点
- 微信公众平台接口程序聊天功能
- shell 调用 sqlplus 各种情况示例
- 使用nohup让程序在远程主机后台运行
- 工作记录---pcap_pkthdr结构详解
- u-boot移植总结(二)LED点灯调试 和 u-boot加载地址
- 通过金矿模型介绍动态规划
- C#弱类型Dataset和强类型Dataset
- beta分布
- 通过金矿模型介绍动态规划
- 用Jsoup进行链接提取