MySql sets several variables from one

I'm starting to pull my hair out here, maybe something like that is possible?

DECLARE var1 int; DECLARE var2 int; DECLARE var3 int; SELECT var1:=id, var2:=foo, var3:=bar from page WHERE name="bob"; CALL someAwesomeSP (var1 , var2 , var3 ); 

The above does not work, but I'm trying to figure out how to do this. My ultimate goal here is to invoke a selection and call a stored procedure with data from select.
Thanks

+7
mysql stored-procedures
source share
3 answers

See how it's done here or here.

I did not have much ability to code in MySQL, and SELECT ... INTO is used in T-SQL to create a temporary table on the fly. I was surprised to learn that it has more functions in MySQL.

+7
source share

It worked for me.

  DECLARE var1 int; DECLARE var2 int; DECLARE var3 int; SELECT id, foo, bar INTO var1, var2, var3 from page WHERE name="bob"; CALL someAwesomeSP (var1 , var2 , var3 ); 

Thanks Zec. The first link helped me understand the correct syntax, or at least what works for me.

+12
source share

For MySQL, please see this sample code:

 -- Init variables SET @var1 = 0; SET @var2 = 0; SET @var3 = 0; SELECT VALUE1, VALUE2, VALUE3 INTO @var1, @var2, @var3 FROM COOL_TABLE WHERE VALUE_ID = 12345; -- Then you can use declared variables SELECT * FROM ANOTHER_TABLE WHERE VALUE1 = @var1 AND VALUE2 = @var2 
+4
source share

All Articles