views:

46

answers:

2

I have created a stored procedure in Mysql, as :

DELIMITER //
CREATE PROCEDURE test()
BEGIN
  SELECT *  FROM buyers;
END //
DELIMITER ;

but when i call it using,

call test()

it returns an error saying :

#1312 - PROCEDURE ticketninja.test1 can't return a result set in the given context

+2  A: 

Statements that return a result set can be used within a stored procedcure but not within a stored function. This prohibition includes SELECT statements that do not have an INTO var_list clause and other statements such as SHOW, EXPLAIN, and CHECK TABLE. For statements that can be determined at function definition time to return a result set, a Not allowed to return a result set from a function error occurs (ER_SP_NO_RETSET). For statements that can be determined only at runtime to return a result set, a PROCEDURE %s can't return a result set in the given context error occurs (ER_SP_BADSELECT).

Maybe you need to utilize a temporary table, like in this example:

The MYYN
it is giving an error :#1172 - Result consisted of more than one row
updated my post; the linked resource contains a full example which you might be able to adjust.
The MYYN
+2  A: 

Make sure your code (or client library) calls mysql_set_server_options() with MYSQL_OPTION_MULTI_STATEMENTS_ON enabled.

Quassnoi