2

This is the function:

FUNCTION GET_ALL(P_USER_ID IN VARCHAR2) RETURN SYS_REFCURSOR IS
   C SYS_REFCURSOR;
BEGIN
    OPEN C
    FOR 'SELECT * FROM XYZ WHERE USER_ID = :P_USER_ID'
    USING P_USER_ID;

    RETURN C;
END;

I'm trying to call this function using NHibernate, like this:

Session
    .CreateSQLQuery("BEGIN ? = PKG.GET_ALL(:P_USER_ID); END;")
    .SetString("P_USER_ID", "SOMEONE")
    .List<XYZ>();

Any code, tips or smoke signs are welcome.

PS: I'm using NHibernate 3.3.0.GA

1

1 Answer 1

1

From the official docs:

For Oracle the following rules apply:

A function must return a result set. The first parameter of a procedure must be an OUT that returns a result set. This is done by using a SYS_REFCURSOR type in Oracle 9 or 10. In Oracle you need to define a REF CURSOR type, see Oracle literature.

There are working tests with full mapping and stored procedure code at https://github.com/nhibernate/nhibernate-core/tree/master/src/NHibernate.Test/SqlTest/Custom/Oracle

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, and my function returns a result set. And it uses sys_refcursor. But... the docs don't say how you put all these things together.
You should have an out parameter, not a return value. See added link.
@DiegoMijelshon really no way to use function that return sys_refcursor? I support some code and this pattern works for NHibernate 3.1 but doesnt work after update NHibernate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.