That's a fierce insert statement to reparse each time. With Oracle you might be lucky because it will find it in its library of recently parsed statements, but all the same...
You want to prepare this statement ahead of time, with something like the following:
my $sth = $db->prepare( qq{ INSERT INTO mf_forms (CLIENT,RECORD,CONTROL,CUSIP,FROMACCT,F_IND,TOACC +T,T_IND, FP,ORIGQTY,DIV,LTCG,STCG,SOCSEC,BKRNO,THIRDPARTYCD,USERID,EDATE, ORIGAMT,CLOSEDIND,ADPSECNO,BRNCH,ACNT,TYPE,CHKDIGIT,PDATE,ACTLQTY, ACTLAMT,CERTIND,REQST,RDATE,COMNTS,TRNFTYPE,FILLER1,ADR_L1,ADR_L2,ADR_ +L3, ADR_L4,ADR_L5,ADR_L6,FILLER_B,CERTNO1,CERTSHRS1,CERTNO2,CERTSHRS2, CERTNO3,CERTSHRS3,CERTNO4,CERTSHRS4,CERTNO5,CERTSHRS5,CERTNO6,CERTSHRS +6 ,CERTNO7,CERTSHRS7,CERTNO8,CERTSHRS8,CERTNO9,CERTSHRS9,CERTNO10,CERTSH +RS10,FILLER_B ) VALUES ( ?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?) }) or die "Cannot prepare statement: ${\$db->errstr}\n";
I might note in passing that you had written VALUE, not VALUES, which will cause an SQL syntax error. In your loop, this prepared statement can then be called thusly:
$sth->execute($CLIENT,$RECORD,$CONTROL,$CUSIP,$FROMACCT,$F_IND,$TOACCT +,$T_IND, $FP,$ORIGQTY,$DIV,$LTCG,$STCG,$SOCSEC,$BKRNO,$THIRDPARTYCD,$USERID,$ED +ATE, $ORIGAMT,$CLOSEDIND,$ADPSECNO,$BRNCH,$ACNT,$TYPE,$CHKDIGIT,$PDATE, $ACTLQTY,$ACTLAMT,$CERTIND,$REQST,$RDATE,$COMNTS,$TRNFTYPE,$FILLER1,$A +DR_L1,$ ADR_L2,$ADR_L3,$ADR_L4,$ADR_L5,$ADR_L6,$FILLER_B,$CERTNO1,$CERTSHRS1,$ +CERTNO2,$CERT SHRS2,$CERTNO3,$CERTSHRS3,$CERTNO4,$CERTSHRS4,$CERTNO5,$CERTSHRS5,$CER +TNO6,$CERTSHR S6,$CERTNO7,$CERTSHRS7,$CERTNO8,$CERTSHRS8,$CERTNO9,$CERTSHRS9,$CERTNO +10,$CERTSHRS10,$FILLER_B) or die "Could not insert: ${\$sth->errstr}\n";
You will note that it is a bit of a bear to create the INSERT statement, and to make sure that you have sufficient ?s (or placeholders) for your columns being inserted. Be lazy, and get Perl to do it for you:
my @columns = qw/ CLIENT RECORD CONTROL CUSIP FROMACCT F_IND TOACCT T_IND FP ORIGQTY DIV LTCG STCG SOCSEC BKRNO THIRDPARTYCD USERID EDATE ORIGAMT CLOSEDIND ADPSECNO BRNCH ACNT TYPE CHKDIGIT PDATE ACTLQTY ACTLAMT CERTIND REQST RDATE COMNTS TRNFTYPE FILLER1 ADR_L1 ADR_L2 ADR_ +L3 ADR_L4 ADR_L5 ADR_L6 FILLER_B CERTNO1 CERTSHRS1 CERTNO2 CERTSHRS2 CERTNO3 CERTSHRS3 CERTNO4 CERTSHRS4 CERTNO5 CERTSHRS5 CERTNO6 CERTSHRS +6 CERTNO7 CERTSHRS7 CERTNO8 CERTSHRS8 CERTNO9 CERTSHRS9 CERTNO10 CERTSH +RS10 FILLER_B /; my $sql = 'inset into mf_forms (' . join( ',', @columns ) . ') values (' . join( ',', ('?') x @columns ) . ')';
This way you eliminate the need to keep the placeholders in sync. Binding the variables remains a problem, but there are ways around that too, although more complex to set in motion. Come to think of it, as you already have an array with the values, you are already set, just pass it as the parameter like this $sth->execute(@data). Easy peasy.
Uh, hang on, you split to @cols and refer to @data. That's not going to work, you know?
In reply to Re: Problem with code
by grinder
in thread Problem with code
by SamueD2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |