MySQL Stored Procedure - how to reference internally created recordset -
i curious how reference existing stored procedure select statement secondary query or set call within same stored procedure.
for example:
create procedure 'mysp' (out sumvalue int) begin -- core recordset sp returns select * table -- want return value based on above recordset set sumvale = sum(previousselect.values) end
essentially, have sp returns detailed recordset, , need return sum , custom values based on data within recordset. issue cannot figure out how reference data after select statement (e.g. create internal reference can use such @recordset1.x).
any appreciated.
try using cursor this link:
as mysql not allow return recordset either store procedures or functions, try this:
create definer=`root`@`localhost` procedure `some_procedure`(out some_id int) begin declare done boolean default false; declare id int; declare tot decimal(10,2); declare some_cursor cursor select id, total some_table id = some_id; declare continue handler not found set done = true; open some_cursor; loop1: loop fetch some_cursor id, tot; if done=true leave loop1; end if; //do calculation here or whatever necessary want code end loop loop1; end;
Comments
Post a Comment