How to get values of several fields in a SELECT inside a STORED PROCEDURE
-
17-04-2021 - |
質問
I am trying to populate my vars the following way.
Obviously, I am doing something wrong.
...
BEGIN
DECLARE p_f1,p_f2 INT;
SELECT
f1 INTO p_f1,
f2 INTO p_f2
FROM
t1
LIMIT 1;
END
What is the proper syntax to populate p_f1 and p_f2?
解決
SELECT
f1,f2
INTO
p_f1,p_f2
FROM
t1
LIMIT 1;
他のヒント
You specify the INTO only once for the entire column/variable list.
BEGIN
DECLARE p_f1,p_f2 INT;
SELECT
f1, f2 INTO p_f1, p_f2
FROM
t1
LIMIT 1;
END
As always, I'm a little concerned whenever I see a LIMIT used without an ORDER BY. Make sure you're consistently getting the same results every time by specifying an explicit order.
You should do this
BEGIN DECLARE p_f1 t1.f1%Type, p_f2 t1.f2%Type;
SELEC1.f2%Typef1,f2 into p_f1, p_f2 FROM t1 LIMIT 1; END
所属していません StackOverflow