3

I have such oracle object:

CREATE OR REPLACE type employee_obj
 AS
 object (
 id NUMBER(10) ,
 ...
 )

stored procedure

function get_employee_obj () return employee_obj is
 l_employee employee_obj;
 begin
 ...
 return l_employee;
 end;

and I need to call it from java code:

 final String QUERY = "begin ? := GET_EMPLOYEE_OBJ(); end;";
 Connection connection = getConnection();
 CallableStatement stmt = connection.prepareCall(QUERY);
 stmt.registerOutParameter(1, <WHAT TO PUT HERE>);
 stmt.execute();
 ResultSet rs = (ResultSet) stmt.getObject(1); 
 ...

What sql or oracle type I need to specify as parameter for registerOutParameter to read object from stored function? I tried several, but allways got PLS-00382: expression is of wrong type error. Thanks!

asked Aug 6, 2010 at 9:31
2

1 Answer 1

4

The correct type for Oracle object is java.sql.Types.STRUCT or oracle.jdbc.OracleTypes.STRUCT depending the level of support you need.

But the trick to get rid of the error PLS-00382: expression is of wrong type is to specify the schema type name. It should be spelled in all upper cases, otherwise you will get invalid name pattern exception.

Given your example, something like that might be appropriate:

stmt.registerOutParameter(1, OracleTypes.STRUCT, "EMPLOYEE_OBJ");

or

stmt.registerOutParameter(1, Types.STRUCT, "EMPLOYEE_OBJ");

After having execute'd the query, you gain access to the result as:

STRUCT result = (oracle.sql.STRUCT)stmt.getObject(1);
Object[] attr = result.getAttributes();
// attr[0] if the first field
// attr[1] the second
// and so on
answered Sep 7, 2014 at 20:56
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, thank you so much Svlvain. I had the "type cannot be null" exception and the "illegal arguments error" for the past 2 days trying to call a Oracle Stored Procedure from my Spring boot application and I tried the NamedStoredProceduredQuery, Query, annotations and then finally just using the SimpleJdbcCall and passing the typeName of STRUCT as the 3rd argument of registering the SqlOutParameter was the key! Dude thank you so much man! I can see the data now too!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.