37,743
社区成员




#!/usr/local/bin/perl -w
use DBI;
use strict;
# represents a DB2 alias cataloged in your DB2 database directory
# my $Database = "dbi:DB2:" + $ARGV[0];
my $Database = "dbi:DB2:TEST";
# represents the user ID used to connect to the database
# my $Username = $ARGV[1];
my $Username = "ming";
# represents the password for the user ID
# my $Password = $ARGV[2];
my $Password = "tian";
# query statement from database
# my $DBQuery = $ARGV[3];
my $DBQuery = "SELECT * FROM MONAH.HELP";
# represents the database handle returned by the connect statement
my $DBConn = DBI->connect($Database, $Username, $Password) or
die "Cannot connect: $DBI::errstr";
# to connect database and prepare the query
my $DBResult = $DBConn->prepare($DBQuery) or
die "Cannot prepare: $DBConn->errstr";
# get the result from database
$DBResult->execute() or
die "Cannot execute: $DBResult->errstr";
#my $RowCount = $DBConn->do($DBQuery);
# check the execution's return code
my $DBState = $DBConn->state;
my $SQLCode = $DBConn->err;
my $Col1;
my $Col2;
# valibles for test the value type
my $numVal;
my $strVal;
$DBResult->bind_col(1, \$Col1);
$DBResult->bind_col(2, \$Col2);
while ($DBResult->fetch) {
if ($Col2 =~ /^\.\d+$/) {
$Col2 = "0" . $Col2;
}
if ($Col2 =~ /^[0-9]+(\.[0-9]{1,100})?$/) {
# valure is a number !
$numVal = $Col2;
$strVal = "NA";
}
else {
# valure is a string !
$numVal = 0;
$strVal = $Col2;
}
print "$Col1|$strVal|$numVal\n";
}
# finished
$DBResult->finish();
# close the connection
$DBConn->disconnect();
my ($numVal, $strVal) = ();
if ($Col2 =~ /\d*\.\d+/) {
$numVal = $Col2 + 0;
$strVal = "NA";
}
else {
$numVal = 0;
$strVal = $Col2;
}
print "$Col1 | $strVal | $numVal\n";
if ($Col2 =~ /^(\d+\.\d+)$/) {