[Phoenix-pm] PERL DBI

Loo, Peter # PHX Peter.Loo at source.wolterskluwer.com
Mon Mar 13 09:03:42 PST 2006


Hi,
 
Not sure if this question is appropriate for this group, but here it is.
 
I am using PERL DBI to SELECTing all columns from a table on Neteeza
database and am INSERTing into an existing table on Oracle.  However,
some of the columns are character based so they require ("") quotes
around the column data to insert.  I need to dynamically built the
INSERT values.  Is there an easy way to quote the column data for the
INSERT statement.  Here are some examples what I am trying to do:
 
    $d_sth = $d_dbh->prepare("select column_name, data_type
                              from   all_tab_columns
                              where  table_name like
upper('%$d_tblName%')
                            ") || die "$DBI::errstr\n";
 
    $d_sth->execute() || die "$DBI::errstr\n";
    while ( $d_arrayref = $d_sth->fetchrow_arrayref() ) {
      if ( @$d_arrayref[1] =~ /CHAR|DATE/ ) {
        $columnsToAssign{ @$_arrayref[0] } = "0";
        }
      }
 
    $s_sth = $s_dbh->prepare("select * from $s_tblName") || die
"$DBI::errstr\n";
    $s_sth->execute() || die "$DBI::errstr\n";
    while ( $s_hashref = $s_sth->fetchrow_hashref ) {
 
 Name                                      Null?    Type
 ----------------------------------------- --------
----------------------------
 DLVRB_GID                                 NOT NULL NUMBER(10)
 PRC_REL_GID                               NOT NULL NUMBER(10)
 PRDCT_GID                                 NOT NULL NUMBER(10)
 BIL_PYMT_TYP_CDE                          NOT NULL CHAR(1)
 PRJTD_TRX_CNT                             NOT NULL NUMBER(10)
 
The column above (BIL_PYMT_TYP_CDE) require quotes for the INSERT
statement.  I would like to dynamically create the INSERT statements
like so:
 
        $columnsToAssign = $columnsToAssign . ", \"" . @$d_arrayref[0] .
"\"";
        }
      else {
        $columnsToAssign = $columnsToAssign . ", " . @$d_arrayref[0];
        }
Is there an easier way?
 
Thanks.
 
Peter Loo
 
 


This E-mail message is for the sole use of the intended recipient(s) and may contain confidential and privileged information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by reply E-mail, and destroy all copies of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/phoenix-pm/attachments/20060313/1d25bd5f/attachment-0001.html


More information about the Phoenix-pm mailing list