sqlplus 传递一个包含 ' 的字符串'例如“索引1”、“索引2”、“索引3”
我需要将此值传递给我的 sql 文件,因为我正在执行带有 IN 的 where 条件。 例如:Delete FROM table WHERE col IN ('index1','index2','index3')
遇到问题
set INDEXES = 'index1','index2','index3'
sqlplus script %INDEXES%
当我尝试使用 sqlplus 命令从 cmd 调用此 sql 文件时 ,只有index1通过还是有问题 我尝试这样做
set INDEXES = "'index1','index2','index3'"
sqlplus script %~INDEXES%
,但也有一个问题
这是我的sql:
Delete FROM table WHERE col IN (&1)
你知道我如何成功传递我需要的字符串吗? 谢谢
I need to pass this value to my sql file cause I am executing then a where condition with a IN.
For instance : Delete FROM table WHERE col IN ('index1','index2','index3')
I have an issue when I try to call this sql file from cmd using sqlplus command
set INDEXES = 'index1','index2','index3'
sqlplus script %INDEXES%
When I do that, only index1 is passed or there is a problem
I tried to do that
set INDEXES = "'index1','index2','index3'"
sqlplus script %~INDEXES%
but there is a problem too
Here is my sql:
Delete FROM table WHERE col IN (&1)
Do you have any idea how I can successfully pass the string I need ?
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Oracle 没有附带内置的字符串标记生成器。所以,我们必须建立自己的。 SO 有几种不同的解决方案。 这是我发布的,它将工作在 10g 或更高。对于早期版本,请尝试这个。
Oracle does not come with a built-in string tokenizer. So, we have to build our own. There are several different solutions on SO. Here is one I published, which will work on 10g or higher. For earlier versions try this one.
事实上,你的技术是正确的。
其中 script.sql 为:
将导致
&1
被逐字替换为'index1','index2','index3'
,从而导致 sqlplus 执行:我看到的问题是删除语句不以分号结尾并且脚本不提交/退出(也许这些只是在您的帖子中排除)。
因此,如果您的命令行正确插入环境变量,则会
产生与我评论中的第一个命令相同的命令。
查看 sqlplus 对命令行参数执行的操作的一个简单方法是将
prompt
添加到脚本中delete
行的开头:Actually, your technique is correct.
where script.sql is:
will result in
&1
being replaced, verbatim, with'index1','index2','index3'
, resulting in sqlplus executing:The problem i see is that the delete statement doesn't end in a semi-colon and the script doesn't commit/exit (maybe those were just excluded in your post).
So it follows that, if your command-line properly interpolates environment variables, then
results in the same command as the first in my comment.
An easy way to see what sqlplus is doing with the command-line parameters is to simply add
prompt
to the beginning of thedelete
line in your script:我会将其视为列表问题中的变量。这些可能很棘手,并且答案会根据您可以访问的 Oracle 版本而有所不同,
您只需将字符串作为 'index1,index2,index3' 传递即可,
这应该可以在 9i+ 上运行
http://asktom.oracle。 com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425
I would look at this as a variable in list question. These can be tricky and the answer varies based on the version of Oracle you have access to
this way you just pass in your string as 'index1,index2,index3'
this should work 9i+
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425