4 Replies Latest reply: May 27, 2012 9:21 AM by indra budiantho RSS

    similar to struct, union or hashtable in c++

    user13328581
      dear experts, this is similar to struct in c++ or union in C++ or hashtable, but can we can create an array in c# and store in it, various variable name and their type. if so, how do we do so. for further explanation...see example below. I want to be able to create anarray(not sure of the terminology to use) called arr and store in it 6, "boy", 'c', null and also its type, for example since 6 is an integer, i store number, since boy is a string, i store varchar2 as well...how do i got about writing a simple code for that. all help is appreciated. Finally, I would also like to pass such array(not sure of the terminology to use) as a parameter. Can someone please explain how to do this without cursors, a simple code will help. I need to understand the idealogy for learning purposes
        • 1. Re: similar to struct, union or hashtable in c++
          VC
          I think you are trying to pass array as parameter to a function or procedure

          Look at this http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:208012348074
          • 2. Re: similar to struct, union or hashtable in c++
            user13328581
            that is not what i am looking for...I will try to expplain it further....

            I have the first procedure/function which returns i would like to store information about the data that being used. so for example if we used the following data like i said

            6 number, null, 'boy' varchar2

            I want to store the following information in a data storage, so that the data storage contains 6 and its associated key type which is number, and then null and its associated key type which is nothing, and boy and its associated key type which is varchar2. I know I can do this with a bit of pain in c++ but i was just wondering how to do this in pl/sql or if possible sql

            Then i would like to use all this information in a function passed as a parameter.
            • 3. Re: similar to struct, union or hashtable in c++
              Solomon Yakobson
              user13328581 wrote:
              that is not what i am looking for...I will try to expplain it further....
              First of all structure and array have nothing in common, so it is difficult to answer correctly when you say "similar to struct in c++ or union in C++ or hashtable". It looks like you need an object:
              CREATE OR REPLACE
                TYPE param_set_type
                  AS OBJECT(
                            param1 NUMBER,
                            param2 NUMBER, -- since second param in your example is NULL I don't know what type to use, so I used NUMER
                            param3 VARCHAR2(100)
                           )
              /
              -- now I can use object type as procedure parameter type
              CREATE OR REPLACE
                PROCEDURE P1(
                             p_param_set param_set_type
                            )
              .
              .
              .
              END;
              /
              -- procedure call
              BEGIN
                  p1(
                     param_set_type
                                   (
                                    6,
                                    null,
                                    'boy'
                                   )
                    );
              end;
              /
              SY.
              • 4. Re: similar to struct, union or hashtable in c++
                indra budiantho
                /* Formatted on 2012/05/27 21:18 (Formatter Plus v4.8.8) */
                DECLARE
                   TYPE assoc_array_type IS TABLE OF VARCHAR2 (200)
                      INDEX BY VARCHAR2 (100);
                
                   v_assoc_arr   assoc_array_type;
                   v_idx         VARCHAR2 (100);
                BEGIN
                   v_assoc_arr ('number') := 5;
                   v_assoc_arr ('nothing') := NULL;
                   v_assoc_arr ('varchar2') := 'boy';
                   v_idx := v_assoc_arr.FIRST;
                
                   WHILE (v_idx IS NOT NULL)
                   LOOP
                      DBMS_OUTPUT.put_line ('key==' || v_idx || ' ; value == ' ||v_assoc_arr (v_idx));
                      v_idx := v_assoc_arr.NEXT (v_idx);
                   END LOOP;
                END;
                output:
                key==nothing ; value ==
                key==number ; value == 5
                key==varchar2 ; value == boy