Call a stored procedure from the DECLARE statement when using cursors in MySQL

Viewed 5001

I am trying to use a cursor in MySQL to call a stored procedure many times. I want to call it as many times as a value for my_id exists in some temporary table, and iterate through those ids and concatenate the results.

Anyway, I'm having trouble with this part of the process:

DECLARE curs CURSOR FOR  
  SELECT something FROM somewhere;

I don't want to select something from somewhere. I want something like

DECLARE curs CURSOR FOR  
  CALL storedproc(@an_id);

Can the DECLARE statement be used to call a stored procedure? Or does it have to be associated with a SELECT only? Googling around, I'm afraid that the latter is the case.

2 Answers
Related