MULTIPLES RETURN IN FUNCTIONS?

Is it possible for a function to return more than one value @ a time.?

user4539121 wrote:
Is it possible for a function to return more than one value @ a time.?A function can only pass back a single return item, however that item may be a data structure containing many values.
There are also pipelined functions which act as tables when incorporated into SQL queries. These effectively open up a pipe and can return one return item after another until it chooses to stop. Example...
SQL> CREATE OR REPLACE TYPE num_descript AS OBJECT(num number, descript varchar2(30))
  2  /
Type created.
SQL>
SQL> CREATE OR REPLACE TYPE tbl_num_descript AS TABLE OF num_descript
  2  /
Type created.
SQL>
SQL>
SQL> CREATE OR REPLACE PACKAGE reftest AS
  2    FUNCTION pipedata(p_choice number) RETURN tbl_num_descript PIPELINED;
  3  END;
  4  /
Package created.
SQL>
SQL> CREATE OR REPLACE PACKAGE BODY reftest AS
  2    FUNCTION pipedata(p_choice number) RETURN tbl_num_descript PIPELINED IS
  3      v_obj num_descript := num_descript(NULL,NULL);
  4      v_rc  sys_refcursor;
  5    BEGIN
  6      IF p_choice = 1 THEN
  7        OPEN v_rc FOR SELECT empno as num, ename as descript FROM emp;
  8      ELSIF p_choice = 2 THEN
  9        OPEN v_rc FOR SELECT deptno as num, dname as descript FROM dept;
10      END IF;
11      LOOP
12        FETCH v_rc INTO v_obj.num, v_obj.descript;
13        EXIT WHEN v_rc%NOTFOUND;
14        PIPE ROW(v_obj);
15      END LOOP;
16      CLOSE v_rc;
17      RETURN;
18    END;
19  END;
20  /
Package body created.
SQL> select * from table(reftest.pipedata(1));
       NUM DESCRIPT
      7369 SMITH
      7499 ALLEN
      7521 WARD
      7566 JONES
      7654 MARTIN
      7698 BLAKE
      7782 CLARK
      7788 SCOTT
      7839 KING
      7844 TURNER
      7876 ADAMS
      7900 JAMES
      7902 FORD
      7934 MILLER
14 rows selected.
SQL> select * from table(reftest.pipedata(2));
       NUM DESCRIPT
        10 ACCOUNTING
        20 RESEARCH
        30 SALES
        40 OPERATIONS
SQL>

Similar Messages

  • How do I get multiple return results from a function

    IDBASKET IDSTAGE DTSTAGE
    3 1 24-JAN-03
    3 5 25-JAN-03
    4 1 13-FEB-03
    4 5 13-FEB-03
    5 3 21-FEB-03
    I input is a single IDBASKET number from this table and this function works fine only if it has one IDSTAGE per idbasket. (idbasket#5)
    But how do I get it to return a result for an IDBASKET when it has multiple IDSTAGE? (idbasket#3 & 4)
    THANKS MUCH,
    MAT
    SQL> CREATE OR REPLACE FUNCTION status_desc_sf
    2 (p_code NUMBER)
    3 RETURN VARCHAR2
    4 IS
    5 lv_output_txt VARCHAR2(30);
    6 BEGIN
    7 IF p_code = 1 THEN lv_output_txt := 'Order submitted';
    8 ELSIF p_code = 2 THEN lv_output_txt := 'Accepted, sent to shipping';
    9 ELSIF p_code = 3 THEN lv_output_txt := 'Backordered';
    10 ELSIF p_code = 4 THEN lv_output_txt := 'Cancelled';
    11 ELSIF p_code = 5 THEN lv_output_txt := 'Shipped';
    12 ELSE lv_output_txt := 'No information';
    13 END IF;
    14 RETURN lv_output_txt;
    15 END;
    16 /

    Duplicate thread:
    How do I get multiple return results from a function

  • Multiple return values (Bug-ID 4222792)

    I had exactly the same request for the same 3 reasons: strong type safety and code correctness verification at compile-time, code readability and ease of mantenance, performance.
    Here is what Sun replied to me:
    Autoboxing and varargs are provided as part of
    JSRs 14 and 201
    http://jcp.org/en/jsr/detail?id=14
    http://jcp.org/en/jsr/detail?id=201
    See also:
    http://forum.java.sun.com/forum.jsp?forum=316
    http://developer.java.sun.com/developer/earlyAccess/adding_generics/index.html
    Multiple return values is covered by Bug-ID 4222792
    Typically this is done by returning an array.
    http://developer.java.sun.com/developer/bugParade/bugs/4222792.html
    That's exactly the problem: we dynamically create instances of array objects that would better fit well within the operand stack without stressing the garbage collector with temporary Array object instances (and with their backing store: 2 separate allocations that need to be recycled when it is clearly a pollution that the operand stack would clean up more efficiently)
    If you would like to engage in a discussion with the Java Language developers, the Generics forum would be a better place:
    http://forum.java.sun.com/forum.jsp?forum=316
    I know that (my report was already refering to the JSR for language extension) Generics is not what I was refering to (even if a generic could handle multiple return values, it would still be an allocated Object
    instance to pack them, i.e. just less convenient than using a static class for type safety.
    The most common case of multiple return values involve values that have known static datatypes and that should be checked with strong typesafety.
    The simple case that involves returning two ints then will require at least two object instances and will not solve the garbage collection overhead.
    Using a array of variable objects is exactly similar, except that it requires two instances for the components and one instance for the generic array container. Using extra method parameters with Integer, Byte, ... boxing objects is more efficient, but for now the only practical solution (which causes the least pollution in the VM allocator and garbage collector) is to use a custom class to store the return values in a single instance.
    This is not natural, and needlessly complexifies many interfaces.
    So to avoid this pollution, some solutions are used such as packing two ints into a long and returning a long, depacking the long after return (not quite clean but still much faster at run-time for methods that need to be used with high frequencies within the application. In some case, the only way to cut down the overhead is to inline methods within the caller code, and this does not help code maintenance by splitting the implementation into small methods (something that C++ can do very easily, both because it supports native types parameters by reference, and because it also supports inline methods).
    Finally, suppose we don't want to use tricky code, difficult to maintain, then we'll have to use boxing Object types to allow passing arguments by reference. Shamely boxed native types cannot be allocated on the operand stack as local variables, so we need to instanciate these local variables before call, and we loose the capacity to track the cases where these local variables are not really initialized by an effective call to the method that will assign them. This does not help debugging, and is against the concept of a strongly typed language like Java should be:
    Java makes lots of efforts to track uninitialized variables, but has no way to determine if an already instanciated Object instance refered in a local variable has effectively received an effective assignment because only the instanciation is kept. A typical code will then need to be written like this:
    Integer a = null;
    Integer b = null;
    if (some condition) {
    //call.method(a, b, 0, 1, "dummy input arg");
    // the method is supposed to have assigned a value to a and b,
    // but can't if a and b have not been instanciated, so we perform:
    call.method(a = new Integer(), b = new Integer(), 0, 1, "dummy input
    arg");
    // we must suppose that the method has modified (not initialized!)
    the value
    // of a and b instances.
    now.use(a.value(), b.value())
    // are we sure here that a and b have received a value????
    // the code may be detected at run-time (a null exception)
    // or completely undetected (the method() above was called but it
    // forgot to assign a value to its referenced objects a and b, in which
    // case we are calling in fact: now.use(0, 0); with the default values
    // or a and b, assigned when they were instanciated)
    Very tricky... Hard to debug. It would be much simpler if we just used:
    int a;
    int b;
    if (some condition) {
    (a, b) = call.method(0, 1, "dummy input arg");
    now.use(a, b);
    The compiler would immediately detect the case where a and b are in fact not always initialized (possible use bere initialization), and the first invoked call.method() would not have to check if its arguments are not null, it would not compile if it forgets to return two values in some code path...
    There's no need to provide extra boxing objects in the source as well as at run-time, and there's no stress added to the VM allocator or garbage collector simply because return values are only allocated on the perand stack by the caller, directly instanciated within the callee which MUST (checked at compile-time) create such instances by using the return statement to instanciate them, and the caller now just needs to use directly the variables which were referenced before call (here a and b). Clean and mean. And it allows strong typechecking as well (so this is a real help for programmers.
    Note that the signature of the method() above is:
    class call {
    (int, int) method(int, int, String) { ... }
    id est:
    class "call", member name "method", member type "(IILjava.lang.string;)II"
    This last signature means that the method can only be called by returning the value into a pair of variables of type int, or using the return value as a pair of actual arguments for another method call such as:
    call.method(call.method("dummy input arg"), "other dummy input arg")
    This is strongly typed and convenient to write and debug and very efficient at run-time...

    Can anyone give me some real-world examples where
    multiple return values aren't better captured in a
    class that logically groups those values? I can of
    course give hundreds of examples for why it's better
    to capture method arguments as multiple values instead
    of as one "logical object", but whenever I've hankered
    for multiple return values, I end up rethinking my
    strategy and rewriting my code to be better Object
    Oriented.I'd personally say you're usually right. There's almost always a O-O way of avoiding the situation.
    Sometimes though, you really do just want to return "two ints" from a function. There's no logical object you can think of to put them in. So you end up polluting the namespace:
    public class MyUsefulClass {
    public TwoInts calculateSomething(int a, int b, int c) {
    public static class TwoInts {
        //now, do I use two public int fields here, making it
        //in essence a struct?
       //or do I make my two ints private & final, which
       //requires a constructor & two getters?
      //and while I'm at it, is it worth implementing
      //equals(), how about hashCode()? clone()?
      //readResolve() ?
    }The answer to most of the questions for something as simple as "TwoInts" is usually "no: its not worth implementing those methods", but I still have to think about them.
    More to the point, the TwoInts class looks so ugly polluting the top level namespace like that, MyUsefulClass.TwoInts is public, that I don't think I've ever actually created that class. I always find some way to avoid it, even if the workaround is just as ugly.
    For myself, I'd like to see some simple pass-by-value "Tuple" type. My fear is it'd be abused as a way for lazy programmers to avoid creating objects when they should have a logical type for readability & maintainability.
    Anyone who has maintained code where someone has passed in all their arguments as (mutable!) Maps, Collections and/or Arrays and "returned" values by mutating those structures knows what a nightmare it can be. Which I suppose is an argument that cuts both ways: on the one hand you can say: "why add Tuples which would be another easy thing to abuse", on the other: "why not add Tuples, given Arrays and the Collections framework already allow bad programmers to produce unmainable mush. One more feature isn't going to make a difference either way".
    Ho hum.

  • Multiple Return Types

    haven't been around in a while, so I thought I'd stir up some comments with a suggestion for a new feature in Java, which I'm sure has been suggested at some point, but I can't remember seeing it talked about, so here goes:
    Multiple Return Types:
    public String, int getStateInfo(String abbrev) {
       if("nj".equalsIgnoreCase(abbrev)) {
          return "New Jersey", 11408042;
       // ... and other states...
       return null, -1;
    String name, int population = getStateInfo("nj");
    System.out.println("The population of " + name + " is " + population + ".");Yes yes, I know. Create a StateInfo object with the fields needed. Still, I think that could be interesting.

    apart from it getting ugly with more than twoparameters
    What? How is this ugly? ;-)
    public String, int, String, Color, String, String
    getStateInfo(String abbrev) {
    return name, population, stateFlower, stateColor,
    or, stateAnimal, governorsName;
    there no indication on what the return valuesrepresent.
    Well, I guees the API docs would have to speak for
    themselves. Or better method naming... In that
    sense, it's no different then now. I could write a
    method "getStateName()" and return totally different.
    public String, int getStateNameAndPopulation(String
    abbrev) {...
    I used to like "tuples" when I studied The Tom Programming Language (that's how he calls them), as every CS student is a bit of a "featurist"... Now that I came to develop 40 hours a week and to love Java's simple and powerful expressiveness, I tend to find such constructs overly ugly to be avoided as possible... a matter of personal taste, too, I suppose...

  • Multiple message deletion functionality disappears

    My iPhones 5S with iOS 8.1 loses multiple message deletion functionality. I tap a message in communication thread, chose more options, mark messages to be deleted and push waste bin. When used a few times the waste bin is replaced with camera options and deleting multiple messages is not possible; see screenshot. In order to re-establish the functionality, I have to close the message app down and restart it. Are there any solutions or work around to this?

    Hi Kare Gronholt,
    If you are having issues with your iPhone's ability to delete multiple messages, you may want to try some things to troubleshoot.
    First, quit all running applications and test again -
    OS: Force an app to close
    Next, I would try restarting the iPhone -
    Turn your iOS device off and on (restart) and reset
    If the issue is still present, you may want to restore the iPhone as a new device -
    How to erase your iOS device and then set it up as a new device or restore it from backups - Apple Support
    Thanks for using Apple Support Communities.
    Best,
    Brett L  

  • MULTIPLE LEAD TIME FUNCTIONALITY

    Hi Guys,
    can anyone explain about "Multiple lead time functionality in SAP".
    whether its related to any particular modules.pls provide any inputs or send some link were i can get this requirements,

    hi
    please refer to this document
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e0901cba-f49e-2910-748c-d7ce4c0c4c1c
    you may find it helpful
    regards
    Aakash Banga

  • Flex services with multiple return types

    Hello,
    We are creating a webapplication with flex and php.
    Everything is working very good, until we got to the library part of the application.
    Every service so far had only 1 return type (eg: User, Group, ...)
    Now for the library we want to return a ArrayCollection of different types of objects. To be more specific the LibraryService should return a ArrayCollection containing Folder and File objects.
    But how to configure this in Flex (Flash Builder 4 (standard))?
    So far it converts every object to the type Object, i would really like it to be Folder or File
    The only solution we can think of right now is to create a new object Library that will contain 2 ArrayCollections, one of type Folder and one of type File. This could work ofcourse, but I wonder if there is a better solution for this OR that i can configure multiple return types for a service.
    Any ideas/advice is greatly appreciated.

    Normally if you are using Blazeds(Java stuff, i'm sure there should be something similar for php), you can map java objects to that of the AS objects, when you get the data back you are actually seeing the object which is a Folder or a File object rather than just a Object.

  • Procedure parameter of type returned by function

    Hi there
    I want to know if it's possible to pass a parameter to procedure of type returned by function
    Something like that
    pocedure test(x in varchar2
    ,y in my_function(param)
    )

    Definitely don't fullish yourself ;-)
    AFAIK you cannot declare a variable based on the return type of a function.
    Perhaps though you are looking for SUBTYPEs.
    SQL> SET SERVEROUTPUT ON;
    SQL> DECLARE
      2    SUBTYPE subtype_name IS VARCHAR2 (30) NOT NULL;
      3
      4    PROCEDURE procedure_name (
      5      parameter_name IN subtype_name)
      6    IS
      7    BEGIN
      8      DBMS_OUTPUT.PUT_LINE (parameter_name);
      9    END;
    10
    11    FUNCTION function_name (
    12      parameter_name IN DATE)
    13      RETURN subtype_name
    14    IS
    15    BEGIN
    16      RETURN TO_CHAR (parameter_name, 'DAY');
    17    END;
    18
    19  BEGIN
    20    procedure_name (function_name (SYSDATE));
    21  END;
    22  /
    THURSDAY
    PL/SQL procedure successfully completed.
    SQL>

  • Display text (returned by function) after tabelar forom submit...

    Hi guys...
    Is there any possibility to display text returned by function after tabular form submit?
    If yes please tell me how :)
    With regards,
    PsmakR

    The value of the selected row's Display column ("Choice B", for example) is not stored in the field -- only the value of the selected row's Value column ("2") is. With the DDLB's item list loaded the form is able to translate "2" (Value) to "Choice B" (Display) so you see "Choice B". With the DDLB's item list empty there is no way to translate "2" to "Choice B" so you see "2".
    If you do not want to save the DDLB's item list with the form you would need to preserve the selected row's Display column in another, possibly hidden, field then use that to display the translated Value.

  • Does Mail (for Lion) have a return receipt function?

    i was wondering whether Mail (for Lion) have a return receipt function. I've seen many negative answers, but they're all from 2007 and earlier. How can I configure for some of my messages to have return receipts?

    chrisrdc wrote:
    Yeah, I do have the home and student Office version, but the trial version for outlook included in the package does not include this feature. Is is available only with the "real"version?
    I'm not sure there is a forum for Office for Mac Product Forums, I'd recommend posting there is no one here is able to help.

  • Advice on Multiple Returns and Unanchored Frames

    Hello everyone--
    I'm hoping to get some guidance on how to approach a problem I'm facing.  I have been tasked with updating a series of documents totalling around 5,000 pages to incorporate our new corporate fonts and colors. The new fonts are slightly larger than the fonts used in those documents. Upon review of the documents, my heart fell as I saw how the indd files were initially built. 
    Here are the lovely challenges:
    The original designers didn't anchor a single image in any of the documents.
    They rarely used text wrap; instead they would use carriage returns and baseline shifts to create the spacing they wanted. 
    Some of the documents have threaded stories that run 60-70 frames long. 
    I was hoping to update the paragraph styles and adjust the layouts as needed based on text flow. (These are training manuals). Nonetheless, as you can imagine, this causes the document to get messy really quick, as text flows to other pages while the associated graphics stay in their original location.
    Due to the number of documents I need to update, some sort of automated solution would be great.  Ideally, I would be able to anchor graphics to the text and remove the extraneous returns so that when the paragraph styles are updated, I can at least maintain the integrity of the content as i work through the other aspects of the layout that I need to update.
    Some ideas:
    Is there maybe a way to see if there is a graphic in the same general location as the multiple returns? Maybe using the some calculation of the offset properties on the first and last return, and then comparing it with the bounds of any graphics on the page? 
    I'm also thinking of splitting the stories and updating each page's styles separately, but the document contains a lot of numbered lists. Splitting the stories would mean I'd need to figure out how to keep all of those lists in the right numbering scheme. 
    I'm not asking for anyone to script this for me. (first of all these may be dumb ideas).  Rather, I would love advice on how to go about scripting something like this (or if it is even possible).  If faced with these challenges, how would you approach them? 
    Thank you in advance for your time and effort! 

    as per my view u have to create tree diffrent tables, because if tree diff. table then multi join can be done

  • Exception in Holder for Multiple Return Types

    Hi,
    I am implementing multiple return types as mentioned at url: -
    http://e-docs.bea.com/wls/docs70/webserv/implement.html#1058020
    I have a "Ticket" object and its holder "TicketHolder".
    I have built the service successfully which has the following method with its
    built files: -
    public String serviceMethod(String arg,TicketHolder out) {
    Ticket tc = new Ticket();
    tc.setticketId("001");
    out = new TicketHolder();
    out.value = tc;
    System.out.println("got it man");
    return arg;
    But when i try to invoke this method from its "http://localhost:8088/WebServices/RegisterTickets"
    link (note - RegisterTickets is the service name here), it gives me the following
    exception at server side as well as client side: -
    javax.xml.rpc.JAXRPCException: Failed to invoke the target:test.MyService@630693
    operation name:serviceMethod method:public java.lang.String test.MyService.serviceMethod(java.lang.String,test.TicketHolder)
    args:[Ljava.lang.Object;@3d51e3arg.length:2 Due to exception:java.lang.IllegalArgumentException:
    argument type mismatch                                                      
                               at weblogic.webservice.component.javaclass.JavaClassInvocationHandler.invoke(JavaClassInvocationHandler.java:97)
                                                   at weblogic.webservice.core.handler.InvokeHandler.handleRequest(InvokeHandler.java:78)
                                                                             at weblogic.webservice.core.HandlerChain.handleRequest(HandlerChain.java:131)
        at weblogic.webservice.core.DefaultOperation.process(DefaultOperation.java:539)
      at weblogic.webservice.core.DefaultWebService.invoke(DefaultWebService.java:264)
    Can someone help me in resolving this exception?
    Any help would be appreciated...
    thanks in advance,
    Rajesh
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    apart from it getting ugly with more than twoparameters
    What? How is this ugly? ;-)
    public String, int, String, Color, String, String
    getStateInfo(String abbrev) {
    return name, population, stateFlower, stateColor,
    or, stateAnimal, governorsName;
    there no indication on what the return valuesrepresent.
    Well, I guees the API docs would have to speak for
    themselves. Or better method naming... In that
    sense, it's no different then now. I could write a
    method "getStateName()" and return totally different.
    public String, int getStateNameAndPopulation(String
    abbrev) {...
    I used to like "tuples" when I studied The Tom Programming Language (that's how he calls them), as every CS student is a bit of a "featurist"... Now that I came to develop 40 hours a week and to love Java's simple and powerful expressiveness, I tend to find such constructs overly ugly to be avoided as possible... a matter of personal taste, too, I suppose...

  • Returned by function MAPIResolveNames

    Hello all.  We have a customer that is trying to export a report and email it.  I will give you the rundown.
    Windows 7
    CR 9 SP 7
    Latest Windows SP
    Outlook 10
    We are getting an error, ERROR 2147500037 RETURNED BY FUNCTION <MAPIRESOLVENAME>
    I read the other threads and didn't seem to be anything in there for CR 9.  Any help would be greatly appreciated.

    Hello,
    Correct. There is no fix for Cr 9 since it's been out of support for 5 years or so.
    Only option is to upgrade to CR 2008 and apply Fix Pack 3.1. Microsoft deprecated simple MAPI API's in Window version 6.1 ( 7 and Server 2008 ) Cr had to update the export dll to use the Extended API set of instructions which is why there is no fix for old versions of CR that had no concept of the Extended set.
    If they can't upgrade then only other option is to ask Microsoft to put the simple MAPI functionality back into all the Products they removed it from. They broke backward compatibility.
    Thank you
    Don

  • Error 2147500037 returned by function MAPIResolveName

    I am getting this error when i am sending  a mail
    MAPI Destination
    Error 2147500037 returned by function <MAPIResolveName>
    its Crystal Report 8.5 with SP3
    Windows Server 2008 R2 Standard
    Windows LIve Mail
    Please suggest

    Upgrade to Crystal Reports 2008 SP 3 and install [Fix Pack 3.5|https://smpdl.sap-ag.de/~sapidp/012002523100006341722011E/cr2008fp35.exe] and then it supports Windows Office 2007 Extended MAPI API's. Microsoft deprecated the Simple MAPI API's in in Office 2007 and above.
    Not supported in CR 8.5, it is 10 years old. Only other option is to ask Microsoft to add the simple MAPI API's back into their new Office Products that use MAPI.
    Thank you
    Don

  • How to returns multiple data with function in varray?

    Hi!
    I have 3 rows in my table and i want the return in VARRAY, but
    in my function bottom it works for only one row of my table.
    I don't know how to have the return of values in 3 rows of my table,
    it's possible to have multiple dimension in varray? Or another way for
    having that? Because i read after in java code this result.
    Now my result are :
    RetVal(1)= 504053
    RetVal(2)= 135058
    RetVal(3)= 206734
    I want like :
    RetVal(1)= 504053 Melanie Brown California
    RetVal(2)= 135058 John Smith Boston
    RetVal(3)= 206734 Roy Smith New York
    CREATE TYPE GPDEV.EMPARRAY is VARRAY(100) OF NUMBER
    CREATE FUNCTION MyName RETURN EMPARRAY
    AS
    l_data EmpArray := EmpArray();
    CURSOR c_emp IS SELECT MyTable
    FROM MyRow
    WHERE clientnumber is not null;
    BEGIN
    FOR MyTable IN c_emp LOOP
    l_data.extend;
    l_data(l_data.count) := MyTable.MyRow
    END LOOP;
    RETURN l_data;
    END;
    Thanks in advance for your help!
    Melanie

    Here is one approach...
    CREATE TYPE testType AS OBJECT (test_letter VARCHAR2(2), test_number NUMBER);
    DECLARE
    CURSOR cAAA IS
    select 'a' test_letter, 1 test_number FROM DUAL UNION ALL
    select 'b' test_letter, 2 test_number FROM DUAL UNION ALL
    select 'c' test_letter, 3 test_number FROM DUAL;
    TYPE vArray_testType is VARRAY(100) OF testType;
    testArray vArray_testType:=vArray_testType();
    y number:=0;
    BEGIN
    dbms_output.put('Adding items to varray...');
    FOR rec in cAAA LOOP
    y:=y+1;
    testArray.extend;
    testArray(y):= testType(
    test_letter => rec.test_letter,
    test_number=> rec.test_number);
    END LOOP;
    dbms_output.put_line('Done. ');
    dbms_output.put_line('Print contents of varray...');
    LOOP EXIT WHEN y = 0;
    dbms_output.put_line(testArray(y).test_letter||' '||testArray(y).test_number);
    y := y-1;
    END LOOP;
    dbms_output.put_line('END');
    END;

Maybe you are looking for