当前位置:网站首页>shell脚本中利用sqlplus操作数据库
shell脚本中利用sqlplus操作数据库
2022-08-10 05:31:00 【DOCKER007】
oracle客户端安装步骤见博文:CSDN
shell操作数据库工具脚本:https://download.csdn.net/upload/10975286
shell脚本中操作数据库时,可以使用sqlplus
#设置数据库连接串
conn=user/[email protected]:1521/SID#定义sql
sqlstr="select sysdate from dual;"#执行sql并获取结果
sql_exc=$( sqlplus $conn <<EOF
$sqlstr
commit;
exit;
EOF
)#echo "sql执行结果:"$sql_exc
这个方法得到的结果很多,除了sql的查询结果,还有很多版本信息等许多无关字符,很难拿到查询结果
所以修改为如下代码,很好的解决了很多打印结果的问题,仅仅打印要查询的结果。
#设置数据库连接串
conn=user/[email protected]:1521/SID#定义sql
sqlstr="select sysdate from dual;"#执行sql并获取结果
sql_exc=$( sqlplus -s /nolog <<EOF
set echo off feedback off heading off underline off;
conn $conn;
$sqlstr
commit;
exit;
EOF
)#echo "sql执行结果:"$sql_exc
边栏推荐
猜你喜欢

论文精度 —— 2016 CVPR 《Context Encoders: Feature Learning by Inpainting》

AVL tree insertion--rotation notes

Read the excerpt notes made by dozens of lightweight target detection papers for literacy

基于Servlet的验证码登陆demo

25张炫酷交互图表,一文入门Plotly

ResNet的基础:残差块的原理

CORS跨域资源共享漏洞的原理与挖掘方法

基本比例尺标准分幅编号流程

Buu Web

How to simulate the background API call scene, very detailed!
随机推荐
利用PyQt5制作YOLOv5的GUI界面
论文精度 —— 2017 ACM《Globally and Locally Consistent Image Completion》
小程序学习笔记:小程序组件间通信方式
网安超基础一周目
Interface documentation evolution illustration, some ancient interface documentation tools, you may not have used it
基本比例尺标准分幅编号流程
笔记1
pytorch框架学习(5)torchvision模块&训练一个简单的自己的CNN (二)
Canal 报错 Could not find first log file name in binary log index file
R中设置图形参数--函数par()详解
Buu Web
网络安全之防火墙
安装Robotics-toolbox-matlab, for 点云坐标系转换
.las转.txt 再转.pcd,编译运行中出现的错误
来亲自手搭一个ResNet18网络
scikit-learn机器学习 读书笔记(一)
【论文笔记1】小样本分类
几种绘制时间线图的方法
Pony语言学习(一):环境配置(续)
使用Google Protobuf 在 Matlab 中工作