oracle 使用 sqlplus 命令在批处理文件中执行 sql 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33396296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:04:07  来源:igfitidea点击:

Execute sql script in batch file with sqlplus command

oraclebatch-filesqlplus

提问by S. Guillaume

I want to execute a PL/SQLscript from a batch file. After some research I wrote this:

我想从批处理文件中执行PL/SQL脚本。经过一番研究,我写了这个:

sqlplus.exe %user%/%pwd%@%db% @c:\users\NDL\SQL\MHUHMS.sql %%l

where user, pwd and db are set before. But here I have to execute the script MHUHMS.sql with one parameter. And it seems that doesn't work; it's giving me an ORA-01017 error and then asking me the user and password. When I give the same values as I used in the batch file it doesn't execute my script.

其中 user、pwd 和 db 是之前设置的。但在这里我必须用一个参数执行脚本 MHUHMS.sql。这似乎不起作用;它给了我一个 ORA-01017 错误,然后问我用户名和密码。当我提供与批处理文件中使用的值相同的值时,它不会执行我的脚本。

screenshotscreenshot

截屏截屏

I've based this on a sqlcmdversion:

我基于一个sqlcmd版本:

SQLCMD -S touoracst01 -U %user% -P %pwd% -d %db% -v l ="%%l" -i c:\users\NDL\SQL\MHUHMS.sql

But there are some questions:

但是有一些问题:

  • Don't I have to pass the parameter -S touoracst01?
  • Is it the right conversion ? Or have I done something wrong ?
  • 我不需要传递参数-S touoracst01吗?
  • 这是正确的转换吗?还是我做错了什么?

I dont' want to modify the SQL script, so I'm hoping the problem is only in the batch file.

我不想修改 SQL 脚本,所以我希望问题只出在批处理文件中。

EDIT : I modify my sqlplus command like this

编辑:我像这样修改我的 sqlplus 命令

sqlplus -L %user%/%pwd%@%db% < "c:\Hardis\NDL\SQL\MHUHMS.sql" %%l

I'm connect ! This part is ok, but it seems that my call of the pl/sqlscript is not good, with the parameters %%l. there is my loop : http://puu.sh/l1Kg2/f66d9c2aa7.pngIf someone can help me. Because the calling with parameters seems good....

我连接!这部分还可以,但是好像我调用的pl/sql脚本不好,参数%%l。有我的循环:http: //puu.sh/l1Kg2/f66d9c2aa7.png如果有人可以帮助我。因为带参数的调用看起来不错....

回答by S. Guillaume

after a lot of research i found this :

经过大量研究,我发现了这一点:

sqlplus -L %user%/%pwd%@%db% @C:\Hardis\NDL\SQL\MHUHMS.sql "%%l"

And the %%l is a variable of my loop. Thank's all for your help !

%%l 是我的循环变量。感谢你的帮助 !