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
SET @variable1 = ( SELECT col1 FROM table1 ); That only allows a single column/variable per statement.
To select multiple columns from a table, simply separate the column names with commas! For example, this query selects two columns, name and birthdate , from the people table: SELECT name, birthdate FROM people; Sometimes, you may want to select all columns from a table.
Your query should be:
SELECT T1.DATE1, T1.DATE2, T1.DATE3
INTO V_DATE1, V_DATE2, V_DATE3
FROM T1
WHERE ID='X';
SELECT
V_DATE1 = T1.DATE1,
V_DATE2 = T1.DATE2,
V_DATE3 = T1.DATE3
FROM T1
WHERE ID='X';
I had problems with Bob's answer but this worked fine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With