views:

28

answers:

2

Hi all,

I searched a lot, but couldn't find anything.. I just want to ask if there's any way to create and call a procedure (Informix) with out parameters. I know how to return one or more values (for procedures and for functions), but this is not what I want. It would be really strange, if Informix does not allow output parameters..

Thanks in advance!

EDIT: Yes, I saw it's possible, but I still can't execute such procedure. For example:

  CREATE PROCEDURE mytest(batch INT,OUT p_out INT)  
  DEFINE inc INTEGER;  
  LET inc = 1;  
  LET p_out = 5;  
  END PROCEDURE;  

and what I receive is:

The routine mytest can not be resolved

and this happens only on executing functions with output parameters..

A: 

Yes, allow..

Check this link: http://publib.boulder.ibm.com/infocenter/idshelp/v115/topic/com.ibm.netpr.doc/ininout.htm?resultof=%22%70%72%6f%63%65%64%75%72%65%22%20%22%70%72%6f%63%65%64%75%72%22%20%22%6f%75%74%22%20%22%70%61%72%61%6d%65%74%65%72%22%20%22%70%61%72%61%6d%65%74%22%20

Cesar Martins
Yes, I saw that soon after I posted my question.. But I still have a error executing such procedure. Here's an example.. I'll edit my post, to be able to format it..
Kiril Kirov
Sorry, but can you tell me what do these mean:Important: You cannot execute UDRs with OUT parameters in DataManipulation Language (DML) SQL statements, except by usingan SLV. The statements SELECT, UPDATE, INSERT and DELETEare DML statements.Important: You cannot use the EXECUTE FUNCTION statement to invoke auser-defined function that contains an OUT parameter, unless youare using JDBC.Important: You cannot execute remote UDRs that contain OUT parameters.
Kiril Kirov
because "Using SLVs: An SLV transmits OUT parameters from a user-defined functionto other parts of an SQL statement. An SLV is local to the SQL statement; thatis, it is valid only for the life of the SQL statement. It provides a temporaryname by which to access an OUT parameter value. Any or all user-definedfunction arguments can be an SLV." SPL Procedures With No Return Values...SPL procedures that do not return values cannot be used in the WHEREclause of a SELECT statement and therefore cannot generate SLVs."
Kiril Kirov
So, does this mean that i cannot do something like: __EXECUTE PROCEDURE mytest(..)__ because mytest does not return anything??Thanks a lot in advance! It's really important..
Kiril Kirov
You would have to call this procedure in a context where an output parameter can be handled. DB-Access is not such an context.
Jonathan Leffler
A: 

Why do you need 'out' parameters? Informix procedures can return multiple values from a single call (or, in this case, a single value):

  CREATE PROCEDURE mytest(batch INT) RETURNING INT AS p_out;
      DEFINE inc INTEGER;
      DEFINE p_out INTEGER;
      LET inc = 1;
      LET p_out = batch + inc;
      RETURN p_out;
  END PROCEDURE;

There are only a limited number of places where you can use an OUT parameter. One is in a query - there is a name SLV (statement local variable) that turns up in some error messages. I believe there's a way to get to OUT parameters via Java (JDBC) too. AFAIK, other APIs do not allow it.

Code written for Informix assumes that it won't need output parameters. Code migrated to Informix from other (impoverished?) systems that do not provide multiple output values from a single procedure need to be rethought to work sensibly with Informix.

Jonathan Leffler