How to trigger a Oracle Stored procedure from Perl with array as input?

不问归期 提交于 2019-12-25 09:09:42

问题


I tried below to get values from DB and pass it as array to oracle procedure.. Can you please check below and let me know where I was doing this wrong ? I couldn't bind the array as input to SP(:1).

$DBHd = DBI->connect( "dbi:Oracle:host=$host;port=$port;sid=$Sid", $user_name, $password);

$DBSth = $DBHd->prepare("SELECT EMP_ID,sal FROM emp");
$DBSth->execute();
my @array_temp;
my @array_source; 
my @array_source_in; 
my @array_source_out;

while (my @array= $DBSth->fetchrow_array())
{
    push (@array_source, [@array[0,1]]);
    push (@array_source_in, @array[0]);
};

my $DBSth2= $OracleDBHd->prepare(q{
                                        BEGIN
                                        $schema.TEST_proc( :1, :2 );
                                        END;
                                    });
my $array_out;
$DBSth2->bind_param( ":1", @array_source_in ); # array_source_in is single dimensional aray and this should be passed as binding variable , This is where I was getting error..
$DBSth2->bind_param_inout( ":2", \$array_out, 0,{ora_type => ORA_RSET } );
unless ($DBSth2->execute())
{
        print "not able to execute proc";
}

while ( my @array2= $array_out->fetchrow_array())
{
    push (@array_source_out, [@array2]);
}

TEST_PROC stored proc will be as below.. ARRAY_NUM_LIST is user defined type ->

  CREATE OR REPLACE TYPE ARRAY_NUM_LIST AS VARRAY(4000) OF NUMBER(20);

CREATE OR REPLACE PROCEDURE TEST_PROC( i_list  IN ARRAY_NUM_LIST, o_curs OUT SYS_REFCURSOR)
AS

BEGIN
          OPEN o_curs
             FOR
                 SELECT emp_ID,fixed_sal,var_sal FROM emp2 WHERE BATCH_ID IN (select column_value from table (i_list));

END;

来源:https://stackoverflow.com/questions/42649731/how-to-trigger-a-oracle-stored-procedure-from-perl-with-array-as-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!