And here is a example of the bug:#!/usr/bin/perl -w use strict; use DBI; my $table = shift; my $dbuser = shift; my $dbpass = shift; my $dbname = shift; my $dbd = 'Oracle'; my $dbh = DBI->connect ( $dbname, $dbuser, $dbpass, $dbd); if (!$dbh) { die "$0 Error conecting to DB ($dbuser/$dbpass\@$dbname); $DBI::er +rstr\n"; } my $SQL = <<SQL; Select * from $table SQL $dbh->{LongReadLen} = 65500; my $sth = $dbh->prepare($SQL) || die $dbh->errstr; $sth->execute(); my $colNames = $sth->{'NAME'}; my $nColumns = $sth->{'NUM_OF_FIELDS'}; print <<DOIT; OPTIONS (ROWS=1) LOAD DATA INFILE * REPLACE INTO TABLE $table FIELDS TERMINATED BY '|' TRAILING NULLCOLS ( DOIT my $colString; for my $colName ( @$colNames ) { $colString .= "\n\t$colName,"; } chop($colString); print "$colString\n"; print<<DOIT; ) BEGINDATA DOIT while ( my @r = $sth->fetchrow_array ) { # print join ( '|', @r ); # This causes another bug of putting 0's where # I wanted || outputted :( # print join ( '|', map ( $_ || '0', trim( @r )) ); # print join ( '|', map ( $_, trim( @r )) ); print "\n"; } $sth->finish || die; $dbh->disconnect; sub trim { my @out = @_; if ( !defined(@_)) {return "";} if ( $#out == -1 ) {return "";} for(@out) { #next if !($_); if (!($_)) { $_ = ""; } s/^\s+//; s/\s+$//; s/\|//g; s/\n//g; s/\cM//g; s/\r//g; } return wantarray ? @out : $out[0]; }
OPTIONS (ROWS=1)
LOAD DATA
INFILE *
REPLACE INTO TABLE DECODE_TABLE
FIELDS TERMINATED BY '|' TRAILING NULLCOLS
(
VALUE,
DESCRIPTION
)
BEGINDATA
1|Something
2|Something else
3|Sometimes
4|Never
5|Always
6|Only once in a while
7|Once in a bluemoon
|All the time
Note the line ...$ sqlplus blah... SQL> select * from DVAL_ADR_AVAIL 2 / V DESCRIPTION - ------------------------------ 1 Something 2 Something else 3 Sometimes 4 Never 5 Always 6 Only once in a while 7 Once in a bluemoon 0 All the time 8 rows selected.Please help! Thanks :)
In reply to getting 0 to print by rbc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |