I need to store select statement results (multiple rows and Columns) in a variable to use later, Is there a way to do it in mySql only. I want to use it in stored procedure.
I know that single result of a select statement can easily be stored in a variable, but is there any to store multiple rows and columns?
If there is. Then What is that and its Ok.
If not then how a scenario like following is solvable in mySql? I have written following ideal/desired code supposing there exists a dataTbale.
Declare dt DataTable;
set dt = select column_name,table_name from information_schema.columns
where table_schema='emp';
DECLARE i INT; DECLARE c INT; set i=0; set c=dt.Rows.Count;
WHILE i < c
@q = concat ('select ', dt.Rows[i][0],' from ',dt.Rows[i][1]);
prepare s1 from @q;
execute s1;deallocate prepare s1;
END WHILE;
Each Row and its two cells of dt are used in while. Is there any facility of two-D array or some other?
What is being tried to do? Above code in while is intended to display all values from all columns (1 by one) from all tables of a database
What is question? Title and 1st Statement of Question.
Instead of storing all the results at once, use a cursor: http://dev.mysql.com/doc/refman/5.0/en/cursors.html
Then loop while reading the cursor.