user12646608
user12646608

Reputation:

Returning Multiple Columns in stored procedure - ORACLE 11.2 Up

Just wondering how I go about returning multiple columns from the database with this stored proc, Thanks.

is 
  cursor sample_cur is  --this can be your select statement
    select name as today from names;


begin
  for rec in sample_cur loop
     -- step by step for each record you return in your cursor
     dbms_output.put_line(rec.name);
  end loop;
end;

Upvotes: 0

Views: 1034

Answers (2)

Ankit Bajpai
Ankit Bajpai

Reputation: 13509

Apart from Manushin's answer, If you strictly wants answer in your format, You may try below -

is 
  cursor sample_cur is  --this can be your select statement
    select name, other_column1, other_column2 as today from names;

begin
  for rec in sample_cur loop
     -- step by step for each record you return in your cursor
     dbms_output.put_line(rec.name || rec.other_column1 || rec.other_column2);
  end loop;
end;

Upvotes: 1

Manushin Igor
Manushin Igor

Reputation: 3689

Cursor can return multiple columns, for example:

procedure list_something(p_result out sys_refcursor) as
begin
    open p_result for
        select t.column1,
               t.column2
        from MY_TABLE t
        where t.column3 is not null;
end;

Next you can iterate thought this cursor from Java/.Net, etc.

Upvotes: 1

Related Questions