0

I need to create a script to return multiple values fetched using pl/sql

script is:

create or replace package body dummy_m  
 is 
  type arr1 is table of temp_particulars.event_start_date%type;  
  var temp_particulars.event_start_date%type;  
      type  c1  is ref cursor
  return temp_date%rowtype;  
    function TEST4(  
 infranchise  IN   temp_particulars.franchise%TYPE,  
      inoperator   IN   temp_particulars.billing_operator%TYPE,  
      inbillingperiod  IN   temp_particulars.billing_period%TYPE,  
      intrafficperiod  IN   temp_particulars.traffic_period_name%TYPE,  
      incost           IN   temp_particulars.unit_cost_used%TYPE  
      )  
      return arr1%rowtype--error  
      is  test1 c1;
    my_arr arr1;
    cnt number; 
  begin
 --my_arr :=arr1();
 cnt:=0;
 delete from temp_date;
      insert into temp_date  SELECT distinct t.event_start_date
        FROM temp_particulars t
       WHERE t.billing_operator = inoperator
         AND t.franchise = infranchise
         AND t.billing_period= inbillingperiod
         AND t.traffic_period_name= intrafficperiod
         and t.unit_cost_used=incost;

     open test1 for select * from temp_date ;

     fetch test1 bulk collect into  my_arr;

     loop

     fetch test1 bulk collect into  my_arr;
     cnt:=cnt+1;

     dbms_output.put_line(cnt);

     exit when test1%notfound;
     end loop; 
      return my_arr; --error 

  close test1;  
  end test4;  
  end;  
/  

here I have to return the value of event_start_date where multiple values are returned but its showing multiple errors like the first error is:

PLS-00371: at most one declaration for 'ARR1' is permitted              

I have even tried this

create or replace package body dummy_m2  
 is   
  type arr1 is table of temp_particulars.event_start_date%type;  
  var temp_particulars.event_start_date%type;  

   type  c1  is ref cursor  
  return temp_date%rowtype;  

  function TEST4(  
 infranchise  IN   temp_particulars.franchise%TYPE,  
      inoperator   IN   temp_particulars.billing_operator%TYPE,  
      inbillingperiod  IN   temp_particulars.billing_period%TYPE,  
      intrafficperiod  IN   temp_particulars.traffic_period_name%TYPE,  
      incost           IN   temp_particulars.unit_cost_used%TYPE  
      )  
      return c1  
      is   
     test1 c1;  
    my_arr arr1;  
    cnt number;   
  begin  
 --my_arr :=arr1();  
 cnt:=0;  
 delete from temp_date;  
      insert into temp_date  SELECT distinct t.event_start_date  
        FROM temp_particulars t  
       WHERE t.billing_operator = inoperator  
         AND t.franchise = infranchise  
         AND t.billing_period= inbillingperiod  
         AND t.traffic_period_name= intrafficperiod  
         and t.unit_cost_used=incost;  

     open test1 for select * from temp_date ;    

  close test1;  
  end test4;  
  end;  

I have even tried this but returns the same error:

PLS-00371: at most one declaration for 'C1' is permitted  

2 Answers 2

1

Is the arr1 type already declared in the package header? It should be, if you intend to call this function from code external to the package; and that would explain why you are getting the error about multiple declarations. Verify that the type is already declared in the header, and remove the declaration from the package body.

More generally, your code looks like a lot of mucking about with cursors for no good reason. All it appears you are trying to do is populate an array with the results of a query. Just do your select directly into the array.

create or replace package body dummy_m  
 is 
  -- This should probably be declared in the package header
  --type arr1 is table of temp_particulars.event_start_date%type;  

    function TEST4(  
      infranchise  IN   temp_particulars.franchise%TYPE,  
      inoperator   IN   temp_particulars.billing_operator%TYPE,  
      inbillingperiod  IN   temp_particulars.billing_period%TYPE,  
      intrafficperiod  IN   temp_particulars.traffic_period_name%TYPE,  
      incost           IN   temp_particulars.unit_cost_used%TYPE  
      )  
      return arr1
      is
        my_arr arr1 := arr1();
  begin
      SELECT distinct t.event_start_date
      BULK COLLECT INTO my_arr
        FROM temp_particulars t
       WHERE t.billing_operator = inoperator
         AND t.franchise = infranchise
         AND t.billing_period= inbillingperiod
         AND t.traffic_period_name= intrafficperiod
         and t.unit_cost_used=incost;

      return my_arr;

  end test4;  
  end;  
/
Sign up to request clarification or add additional context in comments.

1 Comment

thanx.. removing declaration from pkg body in my code n this code.. both worked.
0

The return clause should be:

return arr1  

not:

return arr1%rowtype--error  

Here is some equivalent code that runs without error:

declare
  type arr1 is table of user_tables.last_analyzed%type;  
  var user_tables.last_analyzed%type;  
  type  c1  is ref cursor
      return user_tables%rowtype;  
  function TEST4 (p number)
      return arr1
  is
    test1 c1;
    my_arr arr1;
    cnt number; 
  begin
   null;
  end TEST4;
begin
  null;
end;

3 Comments

This looks suspect: "type c1 is ref cursor return temp_date%rowtype;". Is temp_date a table?
Yes, temp_date is a table having just 1 column where I am inserting the required values as u can see in the code
the above code runs as nothing is being returned.. when u try to use the array n return the same it throws error and even if it doesnt, returns only the last value fetched

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.