多语言展示
当前在线:934今日阅读:176今日分享:34

shell如何调用sqlplus(各种情况示例)

shell 调用 sqlplus 各种情况示例。
工具/原料
1

Linux系统

2

oracle数据库

方法/步骤
1

最简单的shell里调用sqlplus.$ vi test1.sh#!/bin/bashsqlplus -S /nolog  <

2

把sqlplus执行结果传递给shell方法一$ vi test2.sh#!/bin/bashVALUE=`sqlplus -S /nolog <

3

把sqlplus执行结果传递给shell方法二$ vi test3.sh#!/bin/bashsqlplus -S /nolog <

4

把shell程序参数传递给sqlplus$1表示第一个参数, sqlplus里可以直接使用, 赋变量的等号两侧不能有空格不能有空格.$ vi test4.sh#!/bin/bashNAME='$1'sqlplus -S test/test <

5

为了安全要求每次执行shell都手工输入密码$ vi test5.sh#!/bin/bashecho -n 'Enter password for u_test:'read PASSWDsqlplus -S /nolog <

6

为了安全从文件读取密码对密码文件设置权限, 只有用户自己才能读写.$ echo 'test' > u_test.txt$ chmod g-rwx,o-rwx u_test.txt$ vi test6.sh#!/bin/bashPASSWD=`cat u_test.txt`sqlplus -S /nolog <

注意事项
1

二步骤中sqlplus段使用老板键“`”了, 赋变量的等号两侧不能有空格.

2

三步骤中sqlplus段使用 col .. new_value .. 定义了变量并带参数exit, 然后自动赋给了shell的$?

推荐信息