當前位置:首頁 » 操作系統 » 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 07:18:33 瀏覽:675
中信信用卡怎麼設置密碼 發布:2024-09-24 07:18:11 瀏覽:337
sap腳本 發布:2024-09-24 07:16:00 瀏覽:614
演示源碼 發布:2024-09-24 07:13:20 瀏覽:168
android載入地圖api 發布:2024-09-24 07:04:55 瀏覽:521
discuz資料庫安裝 發布:2024-09-24 06:57:19 瀏覽:796
sql查詢一列 發布:2024-09-24 06:42:14 瀏覽:655
我的世界伺服器music指令 發布:2024-09-24 06:16:58 瀏覽:729
路由器怎麼設置上網參數配置 發布:2024-09-24 06:16:17 瀏覽:557
老式電腦配置如何設置 發布:2024-09-24 06:07:08 瀏覽:461