sqloracle-databaseplsqlselect-into

Select multiple columns into multiple variables


How can I do in one select with multiple columns and put each column in a variable?

Something like this:

--code here
V_DATE1 T1.DATE1%TYPE;
V_DATE2 T1.DATE2%TYPE;
V_DATE3 T1.DATE3%TYPE;

SELECT T1.DATE1 INTO V_DATE1, T1.DATE2 INTO V_DATE2, T1.DATE3 INTO V_DATE3
FROM T1
WHERE ID='X';

--code here

Solution

  • Your query should be:

    SELECT T1.DATE1, T1.DATE2, T1.DATE3
    INTO V_DATE1, V_DATE2, V_DATE3
    FROM T1
    WHERE ID='X';