in reply to Re: Re: Passing Arrays from Perl to Stored Procedures
in thread Passing Arrays from Perl to Stored Procedures

If i use individual values instead of a complete array, this will mean i'll have to run this code and execute the procedure for each record insertion, which is be highly inefficient when no. of records is some 100!!

Instead, what i am looking for is parsing the CSV and getting all records into an array and passing it in one-go to the Stored procedure(HOW?) which will then loop through it and insert accordingly

...anyway, thanx!

  • Comment on Re: Passing Arrays from Perl to Stored Procedures

Replies are listed 'Best First'.
Re: Re: Passing Arrays from Perl to Stored Procedures
by dragonchild (Archbishop) on Mar 07, 2003 at 15:51 UTC
    If you use prepare_cached(), it will be quite faster than you think.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Re: Passing Arrays from Perl to Stored Procedures
by Anonymous Monk on Mar 07, 2003 at 21:44 UTC

    As was stated before, 100 records to a database is NOTHING.

    DBD::Oracle apparently does not support passing whole arrays for binding, if it did I'm sure there would be some code behind it that broke the array down to individual elements and bind each of them. So I would suggest something that once you have your statement prepared pass it to a sub like this (untested btw)...

    sub BindValues { my $csr = shift; my $array_ref = shift; my $i; my $placeholder; foreach $i ( 0 .. $#$array_ref ) { $placeholder = ":" . $i; $csr->bind_param($placeholder, $array_ref->[$i]); } }

    Call it like this... BindValues( $csr, \@CSVArray );

    I don't have much experience with Perl and databases, I have some DBD::Oracle experience, but I have more experience in other languages and have yet to see bind parms be anything other than individual elements.

    Like the other post under this one I'm replying to says, prepare_cached makes things much faster and you will find that its not very inefficient at all and that the sub that breaks down your array and individually binds the items will run quite quickly.