Select multiple columns into multiple variables

Hélder Gonçalves picture Hélder Gonçalves · Aug 7, 2013 · Viewed 89.3k times · Source

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

Answer

Your query should be:

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