linux执行sqlplus脚本实例sh

1.与spool一样,linux中调用sqlplus的时候sql语句前不能有tab字符,也不能有空白行。

2.sh中定义变量为:变量名=赋值,sqlplus中引用时用:'${变量名}',例如year=2020,'$year'相当于为'2020',$year相当于2020

shell脚本示例如下:

ORACLE_HOME=/app/product/11.2.0/db
ORACLE_BASE=/app/oracle
ORACLE_SID=对应数据库名称
year=$(/bin/date +%y%y)
echo $year
startdate="$year-01-01"
enddate="$year-12-31"
export ORACLE_HOME ORACLE_BASE ORACLE_SID
PATH=$ORACLE_HOME/bin:/user/bin:/etc:/user/sbin:.

sqlplus  数据库用户/数据库密码<<!

delete from   nx_prp_claim where DF_YEAR='$year';
insert into nx_prp_claim 
select DF_YEAR,COMCODE,classcode,RISKCODE,QUANTITY,AMOUNT,PREMIUM,LOSSQUANTITY,SUMREALPAY,SUMPAID
,decode(nvl(PREMIUM,0),0,0,round(nvl(SUMPAID,0)/PREMIUM,4)) as claimrate
,decode(nvl(QUANTITY,0),0,0,round(nvl(LOSSQUANTITY,0)/QUANTITY,4)) as deathrate
from (
select  
zzz.DF_YEAR
,zzz.COMCODE
,zzz.classcode 
,zzz.RISKCODE 
,zzz.QUANTITY
,zzz.AMOUNT
,zzz.PREMIUM
,zzz.LOSSQUANTITY
,zzz.SUMREALPAY
,nvl(ccc.SUMPAID,0) as SUMPAID 
from 
(

……

commit;
exit
!
 

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页