0

I am using Toad. I have a declaration of a table in a package as follows:

  TYPE MyRecordType IS RECORD
    (ID                      MyTable.ID%TYPE
    ,FIELD1                  MyTable.FIELD1%TYPE
    ,FIELD2                  MyTable.FIELD2%TYPE
    ,FIELD3                  MyTable.FIELD3%TYPE
    ,ANOTHERFIELD            VARCHAR2(80)
    );
  TYPE MyTableType IS TABLE OF MyRecordType INDEX BY BINARY_INTEGER;

There is a procedure (lets say MyProcedure), that is using an object of this table type as input/output. I want to run the procedure and see the results (how the table is filled). So I am thinking I will select the results from the table:

declare
    IO_table           MyPackage.MyTableType;
begin                      
    MyPackage.MyProcedure (IO_table
                      ,parameter1
                      ,parameter2
                      ,parameter3);
    select * from IO_table;
end;

I get the message: Table or view does not exist (for IO_table). If I remove the select line, the procedure runs successfully, but I cannot see its results. How can I see the contents of IO_table after I call the procedure?

3 Answers 3

1

You cannot see the results for a PL/SQL table by using Select * from IO_table

You will need to loop through the collection in the annonymous block. do something like, given in pseudo code below...

       declare
        IO_table           MyPackage.MyTableType;
        l_index        BINARY_INTEGER;
    begin                      
      MyPackage.MyProcedure (IO_table
                  ,parameter1
                  ,parameter2
                  ,parameter3);
       l_index := IO_table.first;

      While  l_index is not null
      loop

      dbms_output.put_line (IO_table(l_index).id);
      .
      .
      .
      .

      l_index :=IO_table.next(l_index_id); 

     end loop;  
     end;      
2
  • I get: wrong number or types of arguments in call to 'NEXT', which strikes me as odd. What could this mean? Jan 17, 2014 at 11:37
  • You just put the index again as a parameter to next: l_index :=IO_table.next(l_index); Thanks, it works fine. Jan 17, 2014 at 11:52
1

You have to do it like this:

select * from TABLE(IO_table);
  • and, of course you missed the INTO or BULK COLLECT INTO clause
4
  • I get the message: cannot access rows from a non-nested table. I found this: stackoverflow.com/questions/896356/…. If I create a type as suggested, the procedure doesn't recognize the new type: wrong number or types of arguments in call Jan 17, 2014 at 10:09
  • Yes, you have to create the type globally with CREATE TYPE ... Jan 17, 2014 at 10:21
  • The thing is that I am not allowed to change the declaration of the type in the procedure, nor the procedure itself. I just need to call the procedure and study the results. Jan 17, 2014 at 11:35
  • Then you have to select into a local PL/SQL table and loop over it as provided in the other answer. Jan 17, 2014 at 11:54
0

1) You can not use associated arrays in SELECT statement, Just nested tables or varrays declared globally. 2) You should use TABLE() expression in SELECT statement 3) You can't simply use SELECT in PL/SQL code - cursor FOR LOOP or REF CURSOR or BULK COLLECT INTO or INTO must be used. 4) The last but not least - please study the manual: http://docs.oracle.com/cd/B28359_01/appdev.111/b28371/adobjcol.htm#ADOBJ00204

Just an example:

    SQL> create type t_obj as object( id int, name varchar2(10));
  2  /

SQL> create type t_obj_tab as table of t_obj;
  2  /

SQL> var rc refcursor
SQL> declare
  2   t_var t_obj_tab := t_obj_tab();
  3  begin
  4   t_var.extend(2);
  5  t_var(1) := t_obj(1,'A');
  6  t_var(2) := t_obj(2,'B');
  7   open :rc for select * from table(t_var);
  8  end;
  9  /

SQL> print rc

        ID NAME                                                                 
---------- ----------                                                           
         1 A                                                                    
         2 B                                                                    

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.