First, why do you want to store the variables in SESSION?
If you can get them inside the procedure, you can also use them inside the procedure.
Again, if you need to return them, you can return a result-set inside your procedure, and catch them in your web-programming or application. Like:
SELECT @var1, @var2
One more thing, I am not really sure I got you right, but if you want the variables from outside(your web-application), you can just pass them as parameters as well. like:
$mysqli->query("CALL procedure_name($parameter1, $parameter2)");
After Question Edit:
I do not understand this..
CURSOR curs FOR
SELECT varName FROM Mytable WHERE typeId = 1;
LOOP
Why use cursor here just to select?
Anyway, I think, you want to use 'varName' next line. You can store it in another variable like:
DECLARE a_variable VARCHAR(50);
SELECT varName INTO a_variable FROM Mytable WHERE typeId = 1;
Here you get the value inside *a_variable*
Use it:
SELECT sqrt(a_variable);//NOT like varName.value
Does this answer your question? Please let me know.
EDIT #3:
I got your question wrong here:
//Should be 1 because var1 =1;
Here is the code you need to use:
SET @query = CONCAT('select SQRT(@', var_name, ') as square_root');
-- SELECT @query;
PREPARE stmt FROM @query;
EXECUTE stmt;
Here is the full procedure I tried this with:
DELIMITER $$
CREATE PROCEDURE `test_var`(
)
BEGIN
DECLARE var1 int;
DECLARE var2 int;
DECLARE var_name varchar(50);
SELECT MyVar1,MyVar2 INTO @var1,@var2 FROM MyValues;
SELECT varName INTO var_name FROM Mytable WHERE typeId = 1;
SET @query = CONCAT('select SQRT(@', var_name, ') as square_root');
-- SELECT @query;
PREPARE stmt FROM @query;
EXECUTE stmt;
END
Hope, this helps. Please let me know.
Regards
Mayukh