当前位置:首页 » 编程软件 » shell脚本oracle数据库

shell脚本oracle数据库

发布时间: 2023-02-01 22:42:15

A. linux下编写以个shell脚本,实现对oracle数据库的查询结果保存在一个变量中

empno=100不存在的,改成有的数据了。
#!/bin/bash
result=$(sqlplus -s 'scott/tiger@dbname'<<EOF
spool test.txt
set pages 0
set feed off
set heading off;
set feedback off;
set verify off;
set linesize 1000;
SELECT * FROM scott.emp where empno=7369;
spool off
EOF
)
echo $result
~
~
~
~
~
~
~
~
~
"test.sh" 14L, 256C written
oracle@****:~> ./test.sh
7369 SMITH CLERK 7902 17-DEC-80 2240.06 20
oracle@****:~> more test.txt
7369 SMITH CLERK 7902 17-DEC-80 2240.06
20

B. shell脚本语言如何和oracle结合在一起使用

如果是通过shell脚本运行Oracle的sql语句,可以这样写shell脚本:
echo “Oracle SQL Example"
sqlplus / as sysdba <<EOF
select * from scott.emp;
EOF
也就是把sql语句写到shell脚本的EOF之间。

C. 如何用shell脚本将在mysql数据库中得到的数据导入到oracle数据库中

有一个工具是mysql到oracle做数据迁移的叫Convert Mysql to Oracle 你可以试试,不知道合不合适。
非要弄shell的话,那可真是麻烦可以选择让程序员写个小程序转换sql的让后用shell调用。
真自己写shell。。。那就折腾导出来的 create、insert语句吧。想想都头大。是在没必要完全用shell弄。

D. 怎么样用shell做一个连接oracle数据库的脚本

shell中直接调用sqlplus即可
sqlplus -s 用户名/口令@实例名<<EOF

E. 写个shell脚本连接oracle数据库查询某表数据导出为txt文件,再发送到第三

1、简单的单列
#!/bin/sh
sqlplus 'user001/12345678'<< EOF
set define off
set hea off
spool vip1.txt
select username from ACCOUNT where LEVEL=7;
spool off
quit;
EOF
sed -i 's/[ ]*//g' ~/vip1.txt
sed -i '/^$/d' ~/vip1.txt
sed -i '1d' ~/vip1.txt
sed -i '$d' ~/vip1.txt
scp -P22 ~/vip1.txt [email protected]:/root
2、复杂的多列
#!/bin/sh
cid=$1;
today=`date +%Y-%m-%d-%H.%M`
ym=`date +%Y%m`
ymd=`date -d -1days +%Y%m%d`
last_ym=`date -d last-month +%Y%m`
next_ym=`date -d next-month +%Y%m`
file=chat_recorder_${cid}_20140707-11.xls

if [[ $1 == '' ]];then
echo "Usage: $0 company_id "
exit 0;
fi
sqlplus 'user002/12345678' << EOF
set linesize 200
set term off verify off feedback off pagesize 999
set markup html on entmap ON spool on preformat off
alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
spool ${file}
select a.*,b.* from recorder_${ym} a,t_${ym} b where a.company_id='$cid' and a.create_time between TO_DATE('2014-07-07 00:00:00', 'YYYY-MM-DD HH24:MI:SS') and TO_DATE('2014-07-12 00:00:00', 'YYYY-MM-DD HH24:MI:SS') and a.chat_id=b.chat_id order by b.chat_id ;
spool off
quit;
EOF
sed -i '/select/d' $file
zip -r ${file}.zip $file
scp -P22 ${file}.zip [email protected]:/opt

F. 求一份shell脚本,需求是:从Oracle数据库中提取一个表中的数据输出到文件,并且每条记录一行;

应用spool命令,大量数据汇出很方便,脚本内容大致如下:
--============================================
#!/bin/sh
#第一步
sqlplus -s 用户名/密码@服务名<<EOF
spool customers.sql --输出文件路径及名称
set trimspool on
set linesize 8000
set pagesize 50000
set newpage 1
set heading off
set term off
set feedback off
set sqlblankline off
SELECT A || '|+|' || --字段A
B || '|+|' || --字段B
C || '|+|' || --字段C
D || '|+|' || --字段D
E || '|+|' || --字段E
F || '|+|' || --字段F
G || '|+|' || --字段G
TO_CHAR(H,'YYYYMMDD HH:MM:SS') || '|+|' --字段H,可以使用函数
FROM CUSTOMERS;--表名
spool off
exit
EOF
--=======================
其中'|+|'为分隔符,也可以换成你说的逗号,即','。调用该脚本后,在根目录下生成customers.sql文件。

G. 怎样在shell脚本中嵌入Oracle数据库操作

在shell里面执行sqlplus,大致如下

sqlplus username/password@sid << EOF >> xxxx.log

select field_name from table_name where ....;

exit;

EOF

然后从输出log里面分析出你要的值

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:750
制作脚本网站 发布:2025-10-20 08:17:34 浏览:1012
python中的init方法 发布:2025-10-20 08:17:33 浏览:719
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:879
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:774
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1127
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:351
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:229
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:912
python股票数据获取 发布:2025-10-20 07:39:44 浏览:876