4 Replies Latest reply: Feb 28, 2013 4:46 AM by BS2012 RSS

    Calling a Table type with a specified value.

    BS2012
      Hi Everyone,

      Please do have a look at this and help me understand.

      Inside a procedure I found a table type
              TYPE r_rates IS RECORD(
              low_rate       growth_rates.low_growth%TYPE  DEFAULT 0
             ,mid_rate       growth_rates.mid_growth%TYPE  DEFAULT 0
             ,high_rate      growth_rates.high_growth%TYPE DEFAULT 0
             ,real_rate      growth_rates.real_growth%TYPE DEFAULT 0);
      But some where I found this table type has been called like
      r_rates(5)
      What's the meaning of this? Please explain me.

      Regards,
      BS2012
        • 1. Re: Calling a Table type with a specified value.
          jeneesh
          Could you post the procedure code?
          • 2. Re: Calling a Table type with a specified value.
            BS2012
            Hi Jeneesh,
            Please see the exact code. Please do have a look at the second line from the execution block.

            lr_member_record := lpt_group_data(ln_ind).member_table(pv_mbr_name);
            What does it mean lpt_group_data(ln_ind) ?

            lpt_group_data   t_group_table;
            
            TYPE t_group_table IS TABLE OF pck_grp_types.r_group_record INDEX BY PLS_INTEGER;
            
            TYPE r_group_record IS RECORD(
            group_data   st_group_string
            ,initial_data st_group_string
            ,member_table t_member_table
            ,full_reset   BOOLEAN);
            
            
            FUNCTION tonumber(pv_owner    IN sd_groups.owner%TYPE
                                 ,pv_grp_name IN sd_groups.groupname%TYPE
                                 ,pv_mbr_name IN sd_groups.varname%TYPE) RETURN NUMBER IS
                    ln_ind   PLS_INTEGER;
                    lr_member_record pck_grp_types.r_member_record;
                    lv_val   VARCHAR2(40);
                    lv_last  VARCHAR2(1);
                    ln_sign  PLS_INTEGER := 1;
                BEGIN
                    ln_ind   := f_get_grp_index(pv_owner, pv_grp_name);
                    lr_member_record := lpt_group_data(ln_ind).member_table(pv_mbr_name);
                    lv_val   := SUBSTR(lpt_group_data(ln_ind).group_data, lr_member_record.start_pos, lr_member_record.entry_length - 1);
                    lv_last  := SUBSTR(lpt_group_data(ln_ind).group_data, lr_member_record.start_pos + lr_member_record.entry_length - 1, 1);
                    IF lv_last IN ('p','q','r','s','t','u','v','w','x','y','}','J','K','L','M','N','O','P','Q','R')
                    THEN
                        lv_val := lv_val || translate(lv_last,'pqrstuvwxy}JKLMNOPQR','01234567890123456789');
                        IF (lr_member_record.entry_type = pck_grp_types.GCV_SIGNED_NUMERIC)
                        THEN
                            ln_sign := -1;
                        END IF;
                    ELSE
                        lv_val := lv_val || translate(lv_last,'{ABCDEFGHI','0123456789');
                    END IF;
                    RETURN(stp.tonumber(lv_val) * ln_sign / lr_member_record.scale);
                END tonumber;
            • 3. Re: Calling a Table type with a specified value.
              rp0428
              >
              lr_member_record := lpt_group_data(ln_ind).member_table(pv_mbr_name);
              What does it mean lpt_group_data(ln_ind) ?
              >
              Well these are the definitions:
              lpt_group_data   t_group_table;
               
              TYPE t_group_table IS TABLE OF pck_grp_types.r_group_record INDEX BY PLS_INTEGER;
              The 't_group_table' is an ASSOCIATIVE ARRAY and you index into that array by providing a PLS_INTEGER value.
              ln_ind   PLS_INTEGER;
              The problem with the code you posted is that the 't_group_table' instance is NOT loaded with any data so there is nothing to reference.

              Normally there would be code to load that associate array with data. If you loaded it with 10 sets of data you could access the third set using
              lpt_group_data(3)
              Your code gets the actual index value to use by calling another function:
              ln_ind   := f_get_grp_index(pv_owner, pv_grp_name);
              Does that help?

              See the 'Associative Array' section of the PL/SQL Language doc
              http://docs.oracle.com/cd/E11882_01/appdev.112/e10472/composites.htm#CHDEIDIC

              There are several code examples in that section.
              • 4. Re: Calling a Table type with a specified value.
                BS2012
                Hi,
                Thanks for sharing all those information.



                Regards,
                BS2012