如何从groovy中存储的函数调用中检索返回值?(How do I retrieve the return value from a stored function call in groovy?)

编程入门 行业动态 更新时间:2024-10-28 09:20:42
如何从groovy中存储的函数调用中检索返回值?(How do I retrieve the return value from a stored function call in groovy?)

我试图在Oracle中调用存储的函数。 此函数不仅具有返回值,还具有OUT参数。 我是Groovy的新手,但有很多数据库经验。 如何检索返回的实际值。 这是我的示例调用...假设我已经有一个很好的数据库连接。

我有一个具有以下签名的商店功能:

GET_JOB(job_id IN VARCHAR2, max_sal OUT INTEGER) RETURNS VARCHAR2

我在groovy中打电话:

def result = sql.call("{? = call get_job(?, ?)}", [Sql.VARCHAR, 'TE', Sql.NUMERIC])

这似乎运行没有错误,但我不知道如何检索返回值和OUT参数(第二个参数)

I am trying to make a call to a stored function in Oracle. This function not only has a return value but also has an OUT parameter. I am relatively new to Groovy but have a lot of database experience. How do I retrieve the actual values returned. Here is my sample call...assume I already have a good database connection.

I have a store function with the following signature:

GET_JOB(job_id IN VARCHAR2, max_sal OUT INTEGER) RETURNS VARCHAR2

I make the call in groovy:

def result = sql.call("{? = call get_job(?, ?)}", [Sql.VARCHAR, 'TE', Sql.NUMERIC])

This seems to run with no errors, but I am unclear as to how to retrieve the return value and the OUT parameter (second parameter)

最满意答案

该方法的int Sql.call(String, List)形式不处理输出参数。 您可以使用void Sql.call(String, List, Closure) 。

sql.call("{? = call get_job(?, ?)}", [Sql.VARCHAR, 'TE', Sql.NUMERIC]) { maxSal -> // do whatever with maxSal }

注意:如果获得存储过程的返回值而不是out参数,请尝试: sql.call(...) { ret, maxSal -> }

The int Sql.call(String, List) form of the method doesn't handle output parameters. You can use void Sql.call(String, List, Closure) instead.

sql.call("{? = call get_job(?, ?)}", [Sql.VARCHAR, 'TE', Sql.NUMERIC]) { maxSal -> // do whatever with maxSal }

Note: If you get the return value of the stored procedure instead of the out parameter, try: sql.call(...) { ret, maxSal -> }

更多推荐

本文发布于:2023-07-15 22:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1119374.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   返回值   retrieve   groovy   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!