Prepare statement failing when using a command line argument for date value

I am executing my script on the command line with parameter ('?')  values for $firstday and $lastday.  I am passing values sysdate-60 and sysdate for these 2 values of '?'  These values are called from a oracle database function of a DATE datatype.  But the script is failing with on a non-numeric character found on  '?'.   When I run the SELECT query by itself on the database, it works and returns rows.

Is the way I have written the prepare statement in call a database function date parameter,  the issue?

My prepare and bind/execute statements are:

my ($db, $user, $pw, $wkdir, $firstday, $lastday)  = @ARGV;
my $gen_text = $dbh->prepare(qq(SELECT col1, col2, col3  FROM region WHERE status = 'Y' and partition_key = (Select common.get_region('REGION',?, ?) from dual)))
                  								or die("Could not get data from table '$_'".DBI->errstr);


Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan SpringerCommented:
Have you tried to escape the "?" with a backslash "\"?
steve2312Author Commented:
Thanks for your suggestion.  I did try to use the backslash with ?, the prepare fails with error message...

Code used:
SELECT common.get_region('REGION',"\"?, "\"?) from dual

Open in new window

illegal zero-length identifier (DBD ERROR: OCIStmtPrepare)

Open in new window

Jan SpringerCommented:
I'm not sure.  Any command that works talking directly to the sql database should work with the proper escaping and quoting from within a perl script.
steve2312Author Commented:
I found the issue was with format of parameter passed on to the database. I needed to use to_date (?,...) function inside the prepare statement and around the bind parameters to resolve the issue.

select ..... , to_date(?,'YYYY-MM-DD'), to_date(?,'YYYY-MM-DD') from dual;

Open in new window

Thanks for the suggestion.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
steve2312Author Commented:
Found out the issue was on the database parameter format and not with Perl Prepare statement error.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.