accessing the return value of called procedure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • -

    accessing the return value of called procedure

    this is one way of creating a stored procedure in mysql:

    CREATE PROCEDURE some_procedure (IN value1, OUT value2)
    BEGIN
    SELECT ... INTO value2 FROM ....
    END//


    and if called from another procedure, i can access the variable this way:

    CREATE PROCEDURE another_procedu re (....)
    BEGIN
    DECLARE count INT;
    ...
    CALL some_procedure( ..., count);
    IF (count ... ) THEN
    END IF;
    ...
    ...
    END//


    there is another way of creating a stored procedure in mysql without
    using a variable:

    CREATE PROCEDURE some_procedure (IN value1)
    BEGIN
    SELECT ... FROM ....
    END//


    if i were to use this way, how can i access the return value?

    CREATE PROCEDURE another_procedu re (....)
    BEGIN
    ...
    CALL some_procedure( ...); <==== how to access the value?
    ...
    ...
    END//


    i tried several ways:

    1) SET count = CALL some_procedure( ...);
    2) IF ((CALL some_procedure( ...)) ...) THEN

    but both produce an error.
  • Bill Karwin

    #2
    Re: accessing the return value of called procedure

    - wrote:[color=blue]
    > i tried several ways:
    >
    > 1) SET count = CALL some_procedure( ...);
    > 2) IF ((CALL some_procedure( ...)) ...) THEN
    >
    > but both produce an error.[/color]

    A procedure that returns a value instead of having an OUT parameter is
    called a FUNCTION. This is created with the CREATE FUNCTION statement.
    Functions are very similar to procedures, except that they cannot
    reference any tables; that is, they can't perform queries.

    Looking in the grammar source code for MySQL 5.0.2, there _appears_ to
    be support for queries of the form:
    SELECT * FROM PROCEDURE procname();
    But I can't get it to work. It might be an unfinished feature. We are
    using 5.0 alpha, after all.

    Is it a problem to use a variable and fill it by passing it as an OUT
    parameter to the procedure?

    Regards,
    Bill K.

    Comment

    Working...