简体   繁体   中英

How to use mybatis to return a value from procedure call?

We call many stored procs using myBatis which have IN / OUT parameters which we know how to handle

But I dont know how to handle when the procedure actually returns a value instead of declaring it as a OUT param

For example using a SQL editor (TOAD for SQL Server) I can run a proc and get a return value as so:

DECLARE @return_value int;

EXEC  @return_value = someProcedure 
    @param1 = 'abc',
    @param2 = 12345

SELECT @return_value as N'@Return Value';

GO

However I have only ever gotten results as either result sets and dont know how to handle this scenario. I thought something like this might work:

<select id="callSomeProcedure" resultType="java.lang.Integer" statementType="CALLABLE">
    { call someProcedure  (
            #{param1},
            #{param2}
    ) }
</select>

But it returns NULL

Any ideas?

OK got it

<select id="callSomeProcedure" statementType="CALLABLE">
    { #{returnVal} = call someProcedure  (
            #{param1},
            #{param2}
    ) }
</select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM