Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Optional Out Parameter

Tyson JougletAug 24 2011 — edited Aug 24 2011
Is there a way to create a procedure where the out parameters are optional? Or an easy way to make it appear that way?

Looking at the code below, I want to be able to call fetch_t99 and be able to use one or more of the "colX" parameters. The idea is that I would not have to write a get_colX function and so that i dont have to make a dummy variable and have multiple lines of clutter code.

As a side note, the reason i am not passing back a rowtype is because I am binding the column values back to items on an apex form.
create table t99 
(
  t99_id number not null , 
  col1 varchar2(20),
  col2 varchar2(20), 
  col3 varchar2(20), 
  constraint t99_pk primary key 
  (
    t99_id 
  )
  enable 
);

insert into t99 values(1,'ONE','TWO','THREE');
commit;

create or replace procedure fetch_t99(
    p_t99_id in  t99.t99_id%type, 
    p_col1   out t99.col1%type,
    p_col2   out t99.col2%type, 
    p_col3   out t99.col3%type
)as
begin
    select col1, col2, col3
      into p_col1, p_col2, p_col3
      from t99
     where t99.t99_id = p_t99_id;
end fetch_t99;

declare
    l_t99_id t99.t99_id%type := 1; 
    l_col1   t99.col1%type;
    l_col2   t99.col2%type; 
    l_col3   t99.col3%type;
begin
    fetch_t99(
        p_t99_id => l_t99_id,
        p_col1   => l_col1,
        p_col2   => l_col2,
        p_col3   => l_col3
    );
    dbms_output.put_line('col1: ' ||l_col1 );
    dbms_output.put_line('col2: ' ||l_col2 );
    dbms_output.put_line('col3: ' ||l_col3 );
end;
Thanks,
Tyson
This post has been answered by Frank Kulash on Aug 24 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 21 2011
Added on Aug 24 2011
4 comments
10,874 views