shell调用各种sqlplus用法
生活随笔
收集整理的這篇文章主要介紹了
shell调用各种sqlplus用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、最簡單的shell里調用sqlplus. $ vi test1.sh #!/bin/bash
sqlplus -S /nolog > result.log < 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 < 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 < 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 < 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 < 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 < conn u_test/$PASSWD
select * from tab;
exit
EOF $ chmod +x test6.sh
$ ./test6.sh --End--
sqlplus -S /nolog > result.log < 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 < 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 < 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 < 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 < 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 < conn u_test/$PASSWD
select * from tab;
exit
EOF $ chmod +x test6.sh
$ ./test6.sh --End--
總結
以上是生活随笔為你收集整理的shell调用各种sqlplus用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 创建Goldengate例外句丙记录跟踪
- 下一篇: oracle数据库中substring的