Reputation: 12352
I have a table in mysql with n rows and columns
col1 col2
a b
c d
...
Using mysql procedures, how would I get all the rows into 1 varchar variable?
DECLARE var varchar(4096);
SET var = <select * from table>
The value of var should be "a b\nc d\n...."
Thank you.
Upvotes: 0
Views: 33
Reputation: 1269743
You could do:
select var := group_concat(col1, ' ', col2 separator '
')
from table;
Seems a bit strange, but it will do what you want.
EDIT:
You can also do:
select var := group_concat(col1, ' ', col2 separator '\n')
from table;
Upvotes: 3