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,roun