如何从 shell 脚本中从引用游标(作为 INOUT 参数传递)检索数据到存储过程?
我有一个从 shell 脚本调用的存储过程。传递给存储过程的参数包括作为 INOUT 参数传递的引用游标。执行存储过程后,我必须检索引用游标返回的数据。如何访问参考游标中的数据?
提前致谢
I have a stored proc which is called from a shell script. The parameters passed to the stored proc includes a reference cursor which is being passed as an INOUT parameter. I have to retrieve the data returned by the reference cursor after executing the stored proc. How do i access the data in the reference cursor?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
shell 脚本正在连接数据库以运行存储过程,对吧?我猜测它正在使用 SQL*Plus 进行连接。假设游标变量是在 SQL*Plus 中声明的,您应该能够简单地打印游标,即
如果您尝试获取 PL/SQL 块中的数据
The shell script is connecting to the database in order to run the stored procedure, right? I'm guessing that it is using SQL*Plus to connect. Assuming that the cursor variable is declared in SQL*Plus, you should be able to simple PRINT the cursor, i.e.
If you are trying to fetch the data in a PL/SQL block
你必须编写类似这样的代码:-
首先像这样创建 SP:-
然后在 shell 脚本中像这样调用 SP:-
输出将是这样的:-
如果你想从 SP 输出中读取特定字段,请参阅此代码下面:-
然后在 shell 脚本中像这样调用 SP:-
如果你仔细观察,SP 返回 3 个字段(impact_type_id,SEVERITY_ORDER) Impact_type_nm,但在 shell 脚本中我只读取 2 个字段(impact_type_id,Impact_type_nm)。
输出将是这样的:-
you will have to write code something like this:-
first create SP like this:-
then in shell script call SP like this:-
output would be something like this:-
if you want to read specific fields from SP output then see this code below:-
then in shell script call SP like this:-
if you will see closely, SP is returning 3 fields(impact_type_id,SEVERITY_ORDER) Impact_type_nm, but in shell script I am reading only 2 fields (impact_type_id, Impact_type_nm).
output would be something like this:-