Hello all gurus,
I am writing a program that fetches counts for each security type that I
pass to a prepared statement. However I have some interesting/funky stuff
going on with my passing params to prepare and the way it handles it. Could
you please take a look at it and tell me what I am missing or
misunderstanding here?
Here is a piece of code that gives a funny result (its trace is included).
iss_typ field is a valid field in FT_T_ISSU table. This statement is
executed perfectly from Oracle prompt when run manually. However it seems
that for some reason the statement does not return an actual value but 0.
my $sth = $dbh->prepare(qq{ SELECT count(DISTINCT isid.instr_id) from
FT_T_ISSU ISSU,FT_T_ISID ISID
where ISSU.iss_typ=? AND
ISID.INSTR_ID=ISSU.INSTR_ID}) || die $dbh->errstr;
my $param="00001";
$sth->execute( $param );
my $tbl_ary_ref = $sth->fetch();
my $count=$tbl_ary_ref->[0];
print "COUNT <$count>\n";
returned result from command prompt: COUNT <0>
its trace:
"trace" 31 lines, 1784 characters
DBI::db=HASH(0x2181cc) trace level set to 3 in DBI 1.15-nothread
-> prepare for DBD::Oracle::db (DBI::db=HASH(0x279da0)~0x2181cc ' SELECT
count(DISTINCT isid.instr_id) from
FT_T_ISSU ISSU,FT_T_ISID ISID
where ISSU.iss_typ=? AND
ISID.INSTR_ID=ISSU.INSTR_ID')
dbih_setup_handle(DBI::st=HASH(0x26ea2c)=>DBI::st=HASH(0x22590c),
DBD::Oracle::st, 26ea38, Null!)
dbih_make_com(DBI::db=HASH(0x2181cc), DBD::Oracle::st, 204)
dbd_preparse scanned 1 distinct placeholders
dbd_st_prepare'd sql SELECT
dbd_describe SELECT (EXPLICIT, lb 80)...
fbh 1: 'COUNT(DISTINCTISID.INSTR_ID)' NULLable, otype 2-> 5,
dbsize 22/134, p38.s0
dbd_describe'd 1 columns (row bytes: 22 max, 4 est avg, cache: 858)
<- prepare= DBI::st=HASH(0x26ea2c) at test_script.pl line 60.
-> execute for DBD::Oracle::st (DBI::st=HASH(0x26ea2c)~0x22590c '00001')
bind :p1 <== '00001' (type 0)
bind :p1 <== '00001' (size 5/6/0, ptype 4, otype 1)
bind :p1 <== '00001' (size 5/5, otype 1, indp 0)
bind :p1 done
dbd_st_execute SELECT (out0, lob0)...
dbd_phs_in ':p1' (0,0): len 5, ind 0
dbd_st_execute SELECT returned (SUCCESS, rpc0, fn4, out0)
<- execute= '0E0' at test_script.pl line 63.
-> fetch for DBD::Oracle::st (DBI::st=HASH(0x26ea2c)~0x22590c)
dbd_st_fetch 1 fields...
dbih_setup_fbav for 1 fields => 0x218028
dbd_st_fetch 1 fields SUCCESS
<- fetch= [ '0' ] at test_script.pl line 65.
-> disconnect for DBD::Oracle::db (DBI::db=HASH(0x279da0)~0x2181cc)
<- disconnect= 1 at test_script.pl line 90.
-> DESTROY for DBD::Oracle::st (DBI::st=HASH(0x22590c)~INNER)
<- DESTROY= undef.
-> DESTROY for DBD::Oracle::db (DBI::db=HASH(0x2181cc)~INNER)
<- DESTROY= undef.
****************************************************************************
***************
If i run the same piece of code without passing iss_typ as param but just
execute the sth, it give me the result i want. But the whole purpose of
prepare is not to prepare it many times. :(
my $sth = $dbh->prepare(qq{ SELECT count(DISTINCT isid.instr_id) from
FT_T_ISSU ISSU,FT_T_ISID ISID
where ISSU.iss_typ='00001'
AND ISID.INSTR_ID=ISSU.INSTR_ID}) || die
$dbh->errstr;
$sth->execute();
my $tbl_ary_ref = $sth->fetch();
my $count=$tbl_ary_ref->[0];
print "COUNT <$count>\n";
returned result from command prompt: COUNT <67586>
its trace:
"trace" 25 lines, 1517 characters
DBI::db=HASH(0x2181cc) trace level set to 3 in DBI 1.15-nothread
-> prepare for DBD::Oracle::db (DBI::db=HASH(0x279da0)~0x2181cc ' SELECT
count(DISTINCT isid.instr_id) from
FT_T_ISSU ISSU,FT_T_ISID ISID
where ISSU.iss_typ='00001' AND
ISID.INSTR_ID=ISSU.INSTR_ID')
dbih_setup_handle(DBI::st=HASH(0x26ea2c)=>DBI::st=HASH(0x22590c),
DBD::Oracle::st, 26ea38, Null!)
dbih_make_com(DBI::db=HASH(0x2181cc), DBD::Oracle::st, 204)
dbd_st_prepare'd sql SELECT
dbd_describe SELECT (EXPLICIT, lb 80)...
fbh 1: 'COUNT(DISTINCTISID.INSTR_ID)' NULLable, otype 2-> 5,
dbsize 22/134, p38.s0
dbd_describe'd 1 columns (row bytes: 22 max, 4 est avg, cache: 858)
<- prepare= DBI::st=HASH(0x26ea2c) at test_script.pl line 60.
-> execute for DBD::Oracle::st (DBI::st=HASH(0x26ea2c)~0x22590c)
dbd_st_execute SELECT (out0, lob0)...
dbd_st_execute SELECT returned (SUCCESS, rpc0, fn4, out0)
<- execute= '0E0' at test_script.pl line 63.
-> fetch for DBD::Oracle::st (DBI::st=HASH(0x26ea2c)~0x22590c)
dbd_st_fetch 1 fields...
dbih_setup_fbav for 1 fields => 0x218028
dbd_st_fetch 1 fields SUCCESS
<- fetch= [ '67586' ] at test_script.pl line 65.
-> disconnect for DBD::Oracle::db (DBI::db=HASH(0x279da0)~0x2181cc)
<- disconnect= 1 at test_script.pl line 90.
-> DESTROY for DBD::Oracle::st (DBI::st=HASH(0x22590c)~INNER)
<- DESTROY= undef.
-> DESTROY for DBD::Oracle::db (DBI::db=HASH(0x2181cc)~INNER)
<- DESTROY= undef.
****************************************************************************
***************************
This code does take params based on INSTR_ID field (is a PK field in table)
It returns an expected result. How would you explain this? Does a prepare
work only on PKs???? I doubt...
my $sth = $dbh->prepare(qq{ SELECT count(DISTINCT isid.instr_id) from
FT_T_ISSU ISSU,FT_T_ISID ISID
where (ISSU.INSTR_ID=? OR ISSU.INSTR_ID=?)
AND ISID.INSTR_ID=ISSU.INSTR_ID}) || die $dbh->errstr;
$sth->execute('0001x5MWFg','0001x5N6YM');
my $tbl_ary_ref = $sth->fetch();
my $count=$tbl_ary_ref->[0];
print "COUNT <$count>\n";
returned result from command prompt: COUNT <2>
its trace:
DBI::db=HASH(0x2181c0) trace level set to 3 in DBI 1.15-nothread
-> prepare for DBD::Oracle::db (DBI::db=HASH(0x279db8)~0x2181c0 ' SELECT
count(DISTINCT isid.instr_id) from
FT_T_ISSU ISSU,FT_T_ISID ISID
where (ISSU.INSTR_ID=? OR ISSU.INSTR_ID=?)
AND ISID.INSTR_ID=ISSU.INSTR_ID')
dbih_setup_handle(DBI::st=HASH(0x26ea44)=>DBI::st=HASH(0x22590c),
DBD::Oracle::st, 26ea50, Null!)
dbih_make_com(DBI::db=HASH(0x2181c0), DBD::Oracle::st, 204)
dbd_preparse scanned 2 distinct placeholders
dbd_st_prepare'd sql SELECT
dbd_describe SELECT (EXPLICIT, lb 80)...
fbh 1: 'COUNT(DISTINCTISID.INSTR_ID)' NULLable, otype 2-> 5,
dbsize 22/134, p38.s0
dbd_describe'd 1 columns (row bytes: 22 max, 4 est avg, cache: 858)
<- prepare= DBI::st=HASH(0x26ea44) at test_script.pl line 60.
-> execute for DBD::Oracle::st (DBI::st=HASH(0x26ea44)~0x22590c
'0001x5MWFg' '0001x5N6YM')
bind :p1 <== '0001x5MWFg' (type 0)
bind :p1 <== '0001x5MWFg' (size 10/11/0, ptype 4, otype 1)
bind :p1 <== '0001x5MWFg' (size 10/10, otype 1, indp 0)
bind :p1 done
bind :p2 <== '0001x5N6YM' (type 0)
bind :p2 <== '0001x5N6YM' (size 10/11/0, ptype 4, otype 1)
bind :p2 <== '0001x5N6YM' (size 10/10, otype 1, indp 0)
bind :p2 done
dbd_st_execute SELECT (out0, lob0)...
dbd_phs_in ':p1' (0,0): len 10, ind 0
dbd_phs_in ':p2' (0,0): len 10, ind 0
dbd_st_execute SELECT returned (SUCCESS, rpc0, fn4, out0)
<- execute= '0E0' at test_script.pl line 63.
-> fetch for DBD::Oracle::st (DBI::st=HASH(0x26ea44)~0x22590c)
dbd_st_fetch 1 fields...
dbih_setup_fbav for 1 fields => 0x2063f4
dbd_st_fetch 1 fields SUCCESS
<- fetch= [ '2' ] at test_script.pl line 65.
-> disconnect for DBD::Oracle::db (DBI::db=HASH(0x279db8)~0x2181c0)
<- disconnect= 1 at test_script.pl line 90.
-> DESTROY for DBD::Oracle::st (DBI::st=HASH(0x22590c)~INNER)
<- DESTROY= undef.
-> DESTROY for DBD::Oracle::db (DBI::db=HASH(0x2181c0)~INNER)
<- DESTROY= undef.
****************************************************************************
***************************
I run this code on both platforms that have perl 5.61 and (DBI-1.15 and
Sun5.6) and (DBI-1.20 and Sun5.8) Versions.
Thanx a lot people for your help.
Daniel Rozengurtel
Analyst II - Data Mining/WHSE
IT Clearing-Settlements
tel: (646) 733-4242
[EMAIL PROTECTED]
_____________________________________________________________________
IMPORTANT NOTICES:
This message is intended only for the addressee. Please notify the
sender by e-mail if you are not the intended recipient. If you are not the
intended recipient, you may not copy, disclose, or distribute this message
or its contents to any other person and any such actions may be unlawful.
Banc of America Securities LLC("BAS") does not accept time
sensitive, action-oriented messages or transaction orders, including orders
to purchase or sell securities, via e-mail.
BAS reserves the right to monitor and review the content of all
messages sent to or from this e-mail address. Messages sent to or from this
e-mail address may be stored on the BAS e-mail system.