use*_*261 2 bash sqlplus oracle11g
我在my .sh文件中的文件(例如ENV=$1 RELEASE_ID=$2)中设置了变量my.sh.我sqlplus进入我的sql文件就好了
sqlplus -S $username/password@destination @/path/copysetup/insert.sql
Run Code Online (Sandbox Code Playgroud)
我想ENV=$1 RELEASE_ID=$2将从unix提示调用的变量传递到我的sql文件中
copysetup.sh env01 release 1.0
Run Code Online (Sandbox Code Playgroud)
从我的sql文件我想将相同的变量传递到oracle表中
insert into table...
Run Code Online (Sandbox Code Playgroud)
有人可以协助如何将变量从bash shell脚本传递到sql文件并最终插入到我的oracle表中吗?
在命令行上传递参数:
sqlplus -S $username/password@destination @/path/copysetup/insert.sql $ENV $RELEASE_ID
Run Code Online (Sandbox Code Playgroud)
然后在SQL脚本中它们变为&1和&2(确保您set scan on位于SQL脚本的顶部)
例如
set scan on
insert into foo (env, release) values ('&1', '&2');
commit;
Run Code Online (Sandbox Code Playgroud)