Reputation: 1821
is it possible to write a PLSQL Select Into Statement for many values?
Pseudocode:
SELECT X,Y,Z INTO v1,v2,v3 FROM.....
If so, can anyone show me an example?
Upvotes: 2
Views: 1017
Reputation: 2505
I know you are asking here about an INSERT INTO statement, but another option I would like to show here is the use of a cursor.
DECLARE
-- Fetch the first 5 entries of the table.
CURSOR cTableA IS
SELECT ColumnA, ColumnB, ColumnC
FROM TableA
WHERE ROWNUM <= 5;
rTableA cTableA%ROWTYPE; --Not realy needed this time, but some think it is neat.
BEGIN
FOR rTableA IN cTableA LOOP
DBMS_OUTPUT.PUT_LINE('ColumnA: ' || rTableA.ColumnA);
DBMS_OUTPUT.PUT_LINE('ColumnB: ' || rTableA.ColumnB);
DBMS_OUTPUT.PUT_LINE('ColumnB: ' || rTableA.ColumnC);
END LOOP;
END;
/
Upvotes: 1
Reputation: 1088
You can use INTO
clause for more than 1 variables. I have created a sample block for you.
declare
x int;
y int;
z int;
begin
select 1,2,3 into x,y,z from dual;
dbms_output.Put_line('x='||x||',y='||y||',z='||z);
end;
Upvotes: 3