用SHELL的循环批量执行SQL语句

--ksh下的一个WHILE 循环的例子
integer i=1
while ((i<67))
do 
  pirnt $i
  i=i+1
done

--ksh 下一个FOR循环的例子
for i in `cat listdate.txt`
do
  echo "执行 $i "
done

--- date.pl 用于生成一个时间段文件

#!/usr/local/bin/perl
use DBI;
if($#ARGV<1)
 {
 die "USAGE:date.pl <startdate> <enddate> /n";
 return(0);
}
$rundate1=$ARGV[0];
$rundate2=$ARGV[1];

$dbh=DBI->connect('dbi:Oracle:host=192.xx.xx.2;sid=ora7','report/system','')||
 die('cann/'t connect to database');
$date=$dbh->prepare("select cal_date from calendar where cal_date between to_date(?,'yyyymmdd') and to_date(?,'yyyymmdd')");
$date->bind_param( 1, $rundate1);
$date->bind_param( 2, $rundate2);
$date->execute;
while (@row = $date->fetchrow_array)
{
printf("$row[0]/n");
}
$dbh->disconnect;


---实例 批处理执行一段时间 每天 要执行的程序

date.pl 20100101 20100307 > listdate.txt
for i in `cat listdate.txt`
do
  echo "执行 $i "
  sqlplus cust/cust @cust_get_jf_md2010.sql $i
done

你可能感兴趣的:(sql,Date,shell,calendar,Integer,database)