In Perl module I have code like this:
...
my $param = 123;
my $sql = "select id, name from obj where id = ?";
$sth = $DBH->prepare($sql) || die $DBH->errstr;
$sth->execute($param) || die $DBH->errstr;
...
whern param has value all is well, but in this module there are conditions when you need to select all rows from table (in my code $param = undef)
Does anyone know how to do this without changing the query?
thx!
I usually prefer to solution provided by bohica, but Oracle can do some strange optimizations, and playing a bit with the query can for some queries get much better performance, or much worse. (Always benchmark any solution)
This will match cust_no = ? when the bind variable is set and cust_no = cust_no when the bind variable is null. Oracle does optimize cust_no = cust_no out usually and just returns all rows.