select sysdate + interval '1' month from dual
...and wanted to make the interval a parameter, you may have tried various permutations, gotten frustrated and just injected a string into the query. There is a solution...
my $query;
eval {
my $sth = $dbi->prepare($query = "select sysdate + interval ? day from dual");
$sth->execute(30);
};
print $@ ? "NOPE: $@\n" : "Winner,winner,chicken dinner!\n$query\n";
eval {
my $sth = $dbi->prepare($query = "select sysdate + interval ? from dual");
$sth->execute("'30' day");
};
print $@ ? "NOPE: $@\n" : "Winner,winner,chicken dinner!\n$query\n";
eval {
my $sth = $dbi->prepare($query = "select sysdate + ? day from dual");
$sth->execute("interval '30' day");
};
print $@ ? "NOPE: $@\n" : "Winner,winner,chicken dinner!\n$query\n";
eval {
my $sth = $dbi->prepare($query = "select sysdate + numtodsinterval(?, 'day') from dual");
$sth->execute("30");
};
print $@ ? "NOPE: $@\n" : "Winner,winner,chicken dinner!\n$query\n";
I have not been able to find any way to directly bind a LITERAL value other than to convert it using the aforementioned function.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.