1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Passing varrays to external procedures

Discussion in 'SQL PL/SQL' started by amit_thombre, May 8, 2009.

  1. amit_thombre

    amit_thombre Guest

    The code is as follows

    --------------------------------------------------------------------------------
    the ext procedure is
    Code (SQL):

    CREATE OR REPLACE FUNCTION pl (x IN va)
       RETURN FLOAT
    AS
    EXTERNAL
       LIBRARY cldll
       NAME "fnClusteringDLL"
       LANGUAGE c
       WITH CONTEXT
       PARAMETERS (
          CONTEXT,
          x BY REFERENCE
       );
    --This means that my function will be defined as:
    --long max(long x, short x_indicator,
    -- long y, short y_indicator, short * ret_indicator)
    /
     
    --here is how it would be used:

    --------------------------------------------------------------------------------

    Teh call to the function is

    Code (SQL):

    CREATE OR REPLACE PROCEDURE cl
    AS
       a         INTEGER;
       b         INTEGER;
       c         NUMBER;
    --TYPE VA IS VARRAY(10) OF NUMBER;
       xvarray   va;
       zvarray   va      := va (10, 11);
    -- yvarray VA:=varray_type(1,2,2,34,5, 7, 8,9,10 );
       yvarray   va      := va (1, 2, 2, 34, 5, 7, 8, 9, 10);
    BEGIN
       DBMS_OUTPUT.ENABLE (1000000);

       SELECT y, x
       BULK COLLECT INTO yvarray, xvarray
         FROM INPUT;

       FOR ELEMENT IN 1 .. yvarray.COUNT
       LOOP
          DBMS_OUTPUT.put_line ('varray.FIRST=' || yvarray (ELEMENT));
          DBMS_OUTPUT.put_line ('varray.FIRST=' || xvarray (ELEMENT));
       END LOOP;

       a := 1;
       c := pl (yvarray);
    --c:= CH(yvarray);
       DBMS_OUTPUT.put_line ('The maximum of ' || c);
    END;
    /
    --------------------------------------------------------------------------------
     
    The C++ function iin the dll is

    Code (Text):
    extern "C" CLUSTERINGDLL_API float fnClusteringDLL(float dxm[])
    //extern "C" CLUSTERINGDLL_API float fnClusteringDLL(float (&dxm)10)
    {
        std::cout<<"Members in the array are "<<dxm[1]<<std::endl;
        std::cout<<"2 Member in the array are "<<dxm[0]<<std::endl;
        printf("Is this printed %f", dxm[0]);
        return dxm[1];
    }
    --------------------------------------------------------------------------------
    Also I have written printf and cout in the function but they do not seem to come as out put any clues as to how to printe these statements and values.
     
  2. tyro

    tyro Forum Genius

    Messages:
    368
    Likes Received:
    20
    Trophy Points:
    260
    Location:
    India
    well i think your question is more suited to a C++ forum than an oracle forum. Your problem is that your C++ code isn't giving output right? Your procedure looks Ok to me.