I created one procedure called Sample1
delimiter ;;
drop procedure if exists Sample1;;
CREATE PROCEDURE Sample1(IN lft1 INT,IN rgt1 INT)
BEGIN
declare emp1 VARCHAR(20);
SELECT emp into emp1 FROM personnell WHERE lft>lft1 and rgt < rgt1;
insert into emp_val values (emp1);
END;;
call Sample1(1,12);;
My Table Structure is like the following:
---------------------
emp lft rgt
---------------------
Albert 1 12
Bert 2 3
Chuck 4 11
Donna 5 6
Eddie 7 8
Fred 9 10
--------------------
It is executing well but i can get the result
IF the executed query having only one row means its coming and inserted that value into the table called emp_val.
but The executed query having more than one row means its showing the following error
Error
SQL query:
call Sample1( 1, 12 )
MySQL said: Documentation
#1172 - Result consisted of more than one row
MY SUGGESTION
I have one suggestion to implementing array on it but how to use it i dont know any one help me..
If your select query can return multiple rows, then you can’t use an intermediate variable to store the query’s results. You can, however, use the
insert ... select ...query format:which does it all in a single statement.