سؤال

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%Type

      f1,f2 into p_f1,
      p_f2   FROM
      t1   LIMIT 1; END
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top