如何在单个命令行中调用存储过程中传递输入参数 [英] How to pass input parameter in stored procedure calling from single command line

查看:418
本文介绍了如何在单个命令行中调用存储过程中传递输入参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何通过单个命令行执行存储过程

  echo execute some_procedure | sqlplus用户名/密码@ databasename 

但我困在程序中传递IN参数,取两个参数。
我尝试了但不工作

  echo execute some_procedure(123,234) sqlplus username / password @ databasename 

如果有人可以帮助我。 p>

解决方案

您显示的内容中,您需要转义括号:

  echo execute some_procedure\(123,234\)| sqlplus username / password @ databasename 

或将命令括在双引号中:

  echoexecute some_procedure(123,234)| sqlplus username / password @ databasename 

要么会阻止shell试图提取parathenses本身,你有一个'语法错误:'('意想不到的或类似的错误。它与Oracle无关,它只是如何shell解释器工作,回传的字符串到SQL * Plus。



顺便说一句,我通常使用一个heredoc这种事情,并避免将凭据放在命令行,通过 ps 可见;例如:

  sqlplus -s / nolog<<!EOF 
connect username / password @ databasename
执行some_procedure(123,234)
exit
!EOF
pre>

I know how to execute stored procedure by single command line

echo execute some_procedure | sqlplus username/password@databasename

But I am stuck how to pass IN parameter in procedure, actually My procedure taking two parameters. I tried this but not working

echo execute some_procedure(123,234) | sqlplus username/password@databasename

It will be great if someone can help me on the same.

解决方案

With what you've shown, you either need to escape the parentheses:

echo execute some_procedure\(123,234\) | sqlplus username/password@databasename

Or enclose your command in double-quotes:

echo "execute some_procedure(123,234)" | sqlplus username/password@databasename

Either will stop the shell trying to intepret the parathenses itself, which would give you an 'syntax error: '(' unexpected or similar error. It's nothing to do with Oracle really, it's just how the shell interpreter works, before it gets as far as piping the echoed string to SQL*Plus.

Incidentally, I'd generally use a heredoc for this sort of thing, and avoid putting the credentials on the command line so they aren't visible via ps; for example:

sqlplus -s /nolog <<!EOF
connect username/password@databasename
execute some_procedure(123,234)
exit
!EOF

这篇关于如何在单个命令行中调用存储过程中传递输入参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆