doubt in arrays used in function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • priyan
    New Member
    • Aug 2007
    • 54

    doubt in arrays used in function

    hai all,
    If anybody know please help me to how to use array in a function and how to return a integer array from a function

    thanks in advance
    priyan.
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Originally posted by priyan
    hai all,
    If anybody know please help me to how to use array in a function and how to return a integer array from a function

    thanks in advance
    priyan.
    Check out below code. I have used ARRAY of CHARACTER. U can reqrite it to INTEGER as required:

    Step:

    [CODE=oracle]

    1. CREATE OR REPLACE TYPE arr_typ AS VARRAY(20) OF VARCHAR2(20);

    2. CREATE OR REPLACE FUNCTION ret_arr(arr_typ e arr_typ) RETURN arr_typ AS
    ar_typ arr_typ;
    BEGIN
    FOR I IN arr_type.FIRST. .arr_type.LAST LOOP
    DBMS_OUTPUT.PUT _LINE(arr_type( i));
    SELECT item BULK COLLECT INTO ar_typ FROM a where type=arr_type(i );
    END LOOP;
    RETURN ar_typ;
    END ret_arr;
    /
    [/CODE]

    Comment

    • priyan
      New Member
      • Aug 2007
      • 54

      #3
      Originally posted by amitpatel66
      Check out below code. I have used ARRAY of CHARACTER. U can reqrite it to INTEGER as required:

      Step:

      [CODE=oracle]

      1. CREATE OR REPLACE TYPE arr_typ AS VARRAY(20) OF VARCHAR2(20);

      2. CREATE OR REPLACE FUNCTION ret_arr(arr_typ e arr_typ) RETURN arr_typ AS
      ar_typ arr_typ;
      BEGIN
      FOR I IN arr_type.FIRST. .arr_type.LAST LOOP
      DBMS_OUTPUT.PUT _LINE(arr_type( i));
      SELECT item BULK COLLECT INTO ar_typ FROM a where type=arr_type(i );
      END LOOP;
      RETURN ar_typ;
      END ret_arr;
      /
      [/CODE]
      Hi amitpatel,
      I can't understand the above program please give me another example in postgresql please i think it is in oracle pl/sql please help me .

      thanks in advance
      priyan

      Comment

      • amitpatel66
        Recognized Expert Top Contributor
        • Mar 2007
        • 2358

        #4
        Originally posted by priyan
        Hi amitpatel,
        I can't understand the above program please give me another example in postgresql please i think it is in oracle pl/sql please help me .

        thanks in advance
        priyan
        Hi Priyan,

        Yes the above code is ORACLE PLSQL. This gives you a logic of how u can write a function with ARRAYS as input parameter and as RETURN value as well.The syntax might differ in POSTGRESQL but the concept will be the s

        Comment

        • priyan
          New Member
          • Aug 2007
          • 54

          #5
          Originally posted by amitpatel66
          Hi Priyan,

          Yes the above code is ORACLE PLSQL. This gives you a logic of how u can write a function with ARRAYS as input parameter and as RETURN value as well.The syntax might differ in POSTGRESQL but the concept will be the s

          hello amitpatel
          Please give me a sample function in postgresql it will be very useful for me. Please do me the help...

          Comment

          • priyan
            New Member
            • Aug 2007
            • 54

            #6
            Originally posted by priyan
            hello amitpatel
            Please give me a sample function in postgresql it will be very useful for me. Please do me the help...

            Please give me examples.......

            Comment

            Working...