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

I am sorry that my statement was quite abstract.

The perl program i am working on is supposed to read a file containing some comma-separated values and load into a table.

Each line of the file containing the comma-separated values represent one record in a table.(there will be nearly 100 such lines). There is a stored procedure which has certain computations and finally inserts the values into the table.

I need to call this stored procedure from the perl program and pass it the records.

thot of storing the Comma-separated values of each record into an array. But as u pointed out, if arrays cannot be passed to stored procedure...then how to go about doing it??

I hope the experience of the monks will help me clear this block...quite urgent, so plz share ur knowledge in this area.

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

Replies are listed 'Best First'.
Re: Passing Arrays from Perl to Stored Procedures
by SheridanCat (Pilgrim) on Mar 07, 2003 at 15:27 UTC
    I think part of the problem we're having is that you are expecting the stored procedure to know what to do with with a Perl array. You need to feed the stored procedure what it likes to eat; not being a stored proc guru, I can't say precisely what stored procs like to eat, but I'm guessing it's not Perl arrays.

    How would the stored procedure know how to unpack the array? Perhaps you could do some sort of binary packing that could then be unpacked by the stored proc, but that's not the kind of thing I'd use a stored procedure for.

    My suggestion is to feed each record to the stored procedure individually. This is a pretty common thing to do.

    By the way, 100 records is nothing. That's test data where I come from. When you start talking in millions and portions of millions things get interesting.

    Also, it seems to me that stuffing everything into an array, passing that array to the proc and having the proc process each record in the array and then insert it is very, very similar to letting perl unpack the array and pass in each record to the proc for further processing and insertion.

    I'm sure this isn't particularly helpful, but may shed some light on a solution for you.

    Regards,

    Cat

Re: Passing Arrays from Perl to Stored Procedures
by Abigail-II (Bishop) on Mar 07, 2003 at 22:10 UTC
    You would do exactly what you do when calling a subroutine in Perl: you pass it a list of arguments. Read the manual page of DBI, or whatever database interface you are using about how to pass parameters to stored procedures.

    But I wouldn't do it that way. It's so.... not SQL-ish. I'd use the database's bulk copy feature to read in the CSV file into a temporary table. Then I'd modify the stored procedure to read the data from the temp table and insert it into the real table. No Perl needed, unless the database isn't able to read in a CSV file (most databases can). In which case I'd write a simple DBI program, using DBI::CVS to read in the CVS file, and DBI::whatever to write it to the temp table.

    Abigail