Linux Shell下执行sqlplus
转载自: http://www.cnblogs.com/include/archive/2011/12/30/2307889.html
以下方法解决了在linux下自动的删除创建用户
sqlplus -S "sys/unimas as sysdba" << !
select to_char(sysdate,'yyyy-mm-dd') today from dual;
exit;
!
!这之间房sql语句就行!
[oracle@hb shell_test]$ cat echo_time
#!/bin/sh
一.最简单的调用sqlplus
sqlplus -S "sys/unimas as sysdba" << !
select to_char(sysdate,'yyyy-mm-dd') today from dual;
exit;
!
[oracle@hb shell_test]$ ./echo_time
TODAY
----------
2011-03-21
-S 是silent mode,不输出类似“SQL>”,连接数据库,关闭数据库之类的信息。
eof可以是任何字符串 比如"laldf"那么当你输入单独一行laldf时"shell认为输入结束,但是必须表示块开始必须使用<<;
开始和结束要匹配这个符号“<<”后面的内容
举例子:
[oracle@hb shell_test]$ sqlplus -s "sys/unimas as sysdba" << abc
> select to_char(sysdate,'yyyy-mm-dd') today from dual;
> exit;
> abc
TODAY
----------
2011-03-21
二.sqlplus的结果传递给shell的方法一
[oracle@hb shell_test]$ cat test2.sh
#!/bin/bash
VALUE=`sqlplus -S "test/unimas" << !
set heading off
set feedback off
set pagesize 0
set verify off
set echo off
select to_char(sysdate,'yyyy-mm-dd') today from dual;
exit
!`
echo $VALUE
if [ -n "$VALUE" ]; then
echo "The rows is $VALUE"
exit 0
else
echo "There is no row"
fi
三.sqlplus的结果传递给shell的方法二
[oracle@hb shell_test]$ cat test1.sh
#!/bin/bash
sqlplus -S "test/unimas" << !
set heading off
set feedback off
set pagesize 0
set verify off
set echo off
col coun new_value v_coun
select count(*) coun from lesson;
exit v_coun
!
VALUE="$?"
echo "show row:$VALUE"
col coun new_value v_coun v_coun为number类型。因为exit 只能返回数值类型。
四.把shell参数传递给sqlplus
#!/bin/bash
t_id="$1"
sqlplus -S "test/unimas" << !
set heading off
set feedback off
set pagesize 0
set verify off
set echo off
select teachername from teacher where id=$t_id;
exit
!
五.sqlplus的结果存储在文件中
#!/bin/sh
sqlplus -S "test/unimas"<<EOF
set heading off
set feedback off
set pagesize 0
set verify off
set echo off
spool spool_file
SELECT * from teacher;
spool off
exit;
EOF
http://blog.chinaunix.net/space.php?uid=9124312&do=blog&id=181372
####################################################################################################################################
查看调度系统状态脚本:
#!/bin/sh
if [[ -z "$1" ]] || [[ "$1" -ne 0 && "$1" -ne 2 ]] #使用[[ ]] 进行逻辑短路操作
then
echo "Please input your parameter: query status[0,2]!"
exit
fi
#for buname in cnlog enlog ItLog JrLog AuLog InnerLog
for buname in cnlog enlog
do
sqlplus -S 'etl/etl@dw_testdb' << abc #使用 << EOF方式输入信息
set line 155
set pages 9999
SELECT /*+ PARALLEL(a,4) */ * FROM $buname.hla_job_rec a where status = $1;
exit
abc
done
Linux Shell下执行sqlplus的更多相关文章
- Linux shell批量执行scp脚本工具
转载: linux shell + expect:批量scp脚本工具 2011-09-13 15:51:06 分类: Python/Ruby 最近在准备一个部署的任务,其中有一 ...
- 转 【MySQL】常用拼接语句 shell 下执行mysql 命令
[MySQL]常用拼接语句 前言:在MySQL中 CONCAT ()函数用于将多个字符串连接成一个字符串,利用此函数我们可以将原来一步无法得到的sql拼接出来,在工作中也许会方便很多,下面主要介绍下几 ...
- Linux shell 下简单的进度条实现
Linux shell 下简单的进度条实现 [root@db145 ~]# cat print_process.sh function Proceess(){ spa='' i= ] do print ...
- 在shell下执行命令的方法
在shell下执行命令的方法 1. #!/bin/sh 语法:在shell.sh的开头写入 #!/bin/sh 一般的shell脚本就是这种用法.这种方法调用脚本开头的shell执行命令,子shell ...
- Linux shell下30个有趣的命令
Tips 原文作者:Víctor López Ferrando 原文地址:30 interesting commands for the Linux shell 这些是我收集了多年的Linux she ...
- linux shell的执行方式
./ ping.sh 这个意思 ,'./'的意思是在当前目录执行, ping.sh----------------------------------------------------------- ...
- Linux Shell 下的输出重定向
linux 环境中支持输入输出重定向,用符号<和>来表示. 0.1和2分别表示标准输入.标准输出和标准错误信息输出, 可以用来指定需要重定向的标准输入或输出,比如 2>a.txt 表 ...
- Linux Shell下”>/dev/null 2>&1“相关知识说明
0:表示键盘输入(stdin)1:表示标准输出(stdout),系统默认是1 2:表示错误输出(stderr) command >/dev/null 2>&1 & == ...
- Linux环境下执行java -jar xxx.jar命令如何让springboot项目在后台运行
段落引用> 由于springboot内置了tomcat容器,我们通常会把项目打成jar或者war后直接使用java -jar xxx.jar命令去运行程序,但是当前ssh窗口被锁定或者按下ctr ...
随机推荐
- Python学习之路3 - 字符串操作&字典
本节内容: 常用的字符串处理. 格式化输出字符串. 字符串的替换. 字符串和二进制的相互转化. 字典的操作 字符串操作 常用的字符串处理 name = 'vector' print(name.capi ...
- EasyJSWebView原理分析
概述 在iOS6之前,native只能调用webiew里的js代码,官方没有提供js调用native方法的接口.到了iOS7,官方提供了JSContext用来与js交互,native和js可以双向调用 ...
- iOS- 用UICollectionViewController 来进行横竖屏九宫格布局
1.简单说说UICollectionViewController 我们在做九宫格布局时,可以使用UIScrollView,也可以使用UICollectionViewController. 当我们用UI ...
- 我爱C语言
各位同志们好,我是来自计算机系的谢畅,我是一个平时看起来高冷其实很逗比的人,我的爱好有很多但只是会一些基础比如游泳,篮球,听听音乐什么的.我的特长是弹吉他虽然弹得不是很溜,我还喜欢朗诵.刚开始我并不是 ...
- 【Docker 命令】- start/stop/restart命令
docker start:启动一个或多少已经被停止的容器 docker stop:停止一个运行中的容器 docker restart :重启容器 语法: docker start [OPTIONS] ...
- sublime text 3103 怎么设置中文
1.shift+ctrl+p调出插件管理,输入install package,按enter键,开始安装. 2.搜索chinese即可,下载安装插件包即可 原文:http://blog.csdn.net ...
- svn checkout不包括根目录
在后面加 “.” 即可,如下: svn co svn://127.0.0.1/ylshop/ . 转载请注明博客出处:http://www.cnblogs.com/cjh-notes/
- 第45天:2017webstrom下载破解汉化
1.webstrom 11.0.3下载地址1:http://pan.baidu.com/s/1kVQjcwf 密码:uggr 下载地址2:http://pan.baidu.com/s/1kVQjcwf ...
- WPF值转换实例
WPF绑定功能非常方便,有时候点击某值时在另t一处显示此值的另一表现形式或调用其对应的其它值,用WPF值转换功能会很方便,下面就一LISTBOX和TEXTBLOCK控件,把LISTBOX中的值转换成除 ...
- 【bzoj1609】[Usaco2008 Feb]Eating Together麻烦的聚餐 dp
题目描述 为了避免餐厅过分拥挤,FJ要求奶牛们分3批就餐.每天晚饭前,奶牛们都会在餐厅前排队入内,按FJ的设想所有第3批就餐的奶牛排在队尾,队伍的前端由设定为第1批就餐的奶牛占据,中间的位置就归第2批 ...