简体   繁体   English

需要将变量值从 shell 脚本传递给 sqlplus sql 文件

[英]Needs to pass variable values to sqlplus sql file from shell script

I am using the Properties file to get the DB connection values and below is shell script file.我正在使用属性文件来获取数据库连接值,下面是 shell 脚本文件。

....
read -p "Please enter start date and end date " para1 para2
source database.prop
for ((i=1;i<=$Dbcount;i++ )); do
sqlplus -S ${user1}/${Password}@${conn} <<EOF &
spool sqlcsvdb_"$i".csv
@squery.sql $para1 $para2
exit;
EOF
done
....

squery.sql file. squery.sql 文件。

....
SET PAGESIZE 50000
SET COLSEP "|"
SET LINESIZE 20000
SET headsep ON
SET FEEDBACK OFF
SET TRIMSPOOL ON
SET TRIMOUT ON
set verify off 
SELECT id|| '|'||date|| '|'|| appid from table where date between '&para1' and '&para2';
exit;
EOF
....

When I execute shell it is not passing the variable values and getting ERROR at line 1:ORA-01722: invalid number error message.当我执行 shell 时,它没有传递变量值并在第 1 行得到 ERROR:ORA-01722: invalid number 错误消息。 Please help me on how to I resolve this and usage of bind variables.请帮助我解决这个问题以及绑定变量的使用。

....
read -p "Please enter start date and end date " para1 para2
Date1=$para1
Date2=$para2
source database.prop
for ((i=1;i<=$Dbcount;i++ )); do
sqlplus -S ${user1}/${Password}@${conn} <<EOF &
spool sqlcsvdb_"$i".csv
@squery.sql $Date1 $Date2
exit;
EOF
done
....
....
SET PAGESIZE 50000
SET COLSEP "|"
SET LINESIZE 20000
SET headsep ON
SET FEEDBACK OFF
SET TRIMSPOOL ON
SET TRIMOUT ON
set verify off 
SELECT id|| '|'||date|| '|'|| appid from table where date between '&1' and '&';
exit;
EOF
....

Defining variables again in the shell script file then passing those variables to sql file works, until it is varaibles are defined within the shell script, it does not work.在 shell 脚本文件中再次定义变量,然后将这些变量传递给 sql 文件有效,直到在 shell 脚本中定义了变量,它不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM