当前位置:首页 » 操作系统 » shell与oracle数据库

shell与oracle数据库

发布时间: 2022-03-07 16:35:02

‘壹’ 写了一个shell脚本连接oracle数据库,但是有问题,麻烦帮看下。

你前面是EOF开始,后面也要EOF结束,而不是用!结束

‘贰’ 怎么样用shell做一个连接oracle数据库的脚本

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

‘叁’ linux系统+oracle数据库+shell脚本都学会了,以后发展会怎么样

如果只是学会,我相信没什么好炫耀的,因为linux+oracle+shell,基本的我都会。建议你精通一到两个就可以了。其他略懂略懂,相信这样的话,你就可以再未来的企业里很好滴发展了。

linux+oralce是很多大型企业用的很多的操作系统和数据库,精通了这两门,你过万月薪根本没问题。加油吧GG或MM

‘肆’ 用shell怎样连接oracle数据库

用 sqlplus 连接

‘伍’ shell连接oracle数据库,需要下载什么东西么 这linux系统刚刚装上 什么都没有

装个oracle client,用sqlplus连接

‘陆’ shell脚本语言如何和oracle结合在一起使用

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

‘柒’ 写个脚本使用perl或shell对比oracle表数据,急啊,高分悬赏!

perl脚本如下,执行的结果会放在与表对应的csv文件中,有些代码折行了,请在折行的代码区域双击一下即可展开。


#!/usr/bin/envperl
usestrict;
usewarnings;
useDBI;

#****说明****#

#假设:
#两个database分别为db1,db2
#两个table分别为tbl1,tbl2
#从Oracle数据库导出的文件为csv格式(逗号分隔),分别为tbl1.csv,tbl2.csv

#****执行步骤****#

#Step1连接Oracle数据库
$dbname1="db1";
$dbname2="db2";
$user="user";
$passwd="password";
$dbh1=DBI->connect("DBI:Oracle:$dbname1",$user,$passwd)||die"cannotconnecttoOracle:$! ";
$dbh2=DBI->connect("DBI:Oracle:$dbname2",$user,$passwd)||die"cannotconnecttoOracle:$! ";

#Step2导出数据库中的tables到csv文件
db_to_csv($dbh1,'tbl1.csv','SELECT*FROMdb1.tbl1');
db_to_csv($dbh2,'tbl2.csv','SELECT*FROMdb2.tbl2');

#Step3断开数据库连接
$dbh1->disconnect;
$dbh2->disconnect;

#Step4将比较结果写入文件compare_results.csv中
open(my$fh,'>','compare_results.csv')ordie$!;
compare_mp('tbl1.csv','tbl2.csv',$fh);
close$fh;

#****以下为一些自定义subroutines****#

#从数据库读取数据并导出为csv文件
subdb_to_csv
{
my$dbh=shift;
my$file=shift;
my$sql=shift;

my$sth=$dbh->prepare($sql);
$sth->execute;
my$numFields=$sth->{'NUM_OF_FIELDS'};

open(my$fh,'>',$file)ordie$!;
while(my$ref=$sth->fetchrow_arrayref){
my$file;
for(my$i=0;$i<$numFields;$i++){
$line.=$$ref[$i]if(defined$$ref[$i]);
$line.=",";
}
printf$fh("%s ",$line);
}
close$fh;
}

#对比两个表并输出同colum不同值的lines
subcompare_mp{
my$file1=shift;
my$file2=shift;
my$fh_result=shift;

open(my$fh1,'<',$file1)ordie$!;
open(my$fh2,'<',$file2)ordie$!;

my(@col1,@col2,@col3,@col4);
while(defined(my$line1=<$fh1>)){
chomp$line1;
my($tbl1_col1,$tbl1_col2,$tbl1_col3,$tbl1_col4)=($line1=~/(w+),(w+),(w+),(w+)/);

my$line2=chomp(<$fh2>);
my($tbl2_col1,$tbl2_col2,$tbl3_col3,$tbl4_col4)=($line1=~/(w+),(w+),(w+),(w+)/);

if($tbl1_col1!~/$tbl2_col1){
push@col1,[$tbl1_col1,$tbl2_col1];
}

if($tbl1_col2!~/$tbl2_col2){
push@col2,[$tbl1_col2,$tbl2_col2];
}

if($tbl1_col3!~/$tbl2_col3){
push@col3,[$tbl1_col3,$tbl2_col3];
}

if($tbl1_col4!~/$tbl2_col4){
push@col4,[$tbl1_col4,$tbl2_col4];
}
}

close$fh1;
close$fh2;

#写入不同的值column1
printf$fh_result("%-8s %-8s ",'AREAID_tbl1','AREAID_tbl2');
formy$ref_elem(@col1){
printf$fh_result("%-8s %-8s ",${$ref_elem}[0],@${$ref_elem}[1]);
}
#写入不同的值column2
printf$fh_result("%-8s %-8s ",'CODED_tbl1','CODE_tbl2');
formy$ref_elem(@col2){
printf$fh_result("%-8s %-8s ",${$ref_elem}[0],@${$ref_elem}[1]);
}
#写入不同的值column3
printf$fh_result("%-8s %-8s ",'AREANO_tbl1','AREANO_tbl2');
formy$ref_elem(@col3){
printf$fh_result("%-8s %-8s ",${$ref_elem}[0],@${$ref_elem}[1]);
}
#写入不同的值column4
printf$fh_result("%-8s %-8s ",'AREANNAME_tbl1','AREANNAME_tbl2');
formy$ref_elem(@col4){
printf$fh_result("%-8s %-8s ",${$ref_elem}[0],@${$ref_elem}[1]);
}
}

楼主真没素质,写这么多也不给分。

‘捌’ 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

‘玖’ 如何在shell脚本中嵌入Oracle数据库操作

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

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

select field_name from table_name where ....;

exit;

EOF

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

‘拾’ 写个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

热点内容
电视系统密码是多少 发布:2024-09-24 09:15:38 浏览:270
我手机的密码是什么 发布:2024-09-24 08:50:53 浏览:12
pythonlist转换str 发布:2024-09-24 08:40:25 浏览:564
怎么通过crt连接阿里云服务器 发布:2024-09-24 08:30:42 浏览:85
丰巢快递柜的密码是多少 发布:2024-09-24 08:10:33 浏览:500
高级java学习 发布:2024-09-24 07:57:20 浏览:887
访问书访问 发布:2024-09-24 07:47:28 浏览:142
强混合加密 发布:2024-09-24 07:46:03 浏览:288
android可见性 发布:2024-09-24 07:29:08 浏览:18
大通g20房车哪个配置性价比高 发布:2024-09-24 07:28:29 浏览:232