How to use date variables in SELECT Statement within SQLPLUS?

How to use date variables in SELECT Statement within SQLPLUS?
I need to pass to a SQL query some dates obtained from a previous select query.

I have this code:
sqlplus -s /nolog > /dev/null 2>&1 <<EOF
connect myusername/mypassword

set echo off
set feedback off
set linesize 500
set pagesize 0
set sqlprompt ''
set term off
set verify off
set trimspool on

column dcolmin new_value begdate noprint
column dcolmax new_value enddate noprint

select mindate dcolmin, maxdate dcolmax from mytable;

spool /mydirectory/myfile.csv

select <my code> from mytable_1 a
where a.check_date between &begdate. and &enddate.
This error is written to the output file:
and a.check_date between 26-FEB-10 and 19-MAR-10
ERROR at line 21:
ORA-00904: "MAR": invalid identifier
(Please note that the dates are correct.  Please also note that if the dates
for the check_date are hardcoded, the query works OK:

and a.check_date between '26-FEB-2010' and '19-MAR-2010' - WORKS FINE!

What is a right way to use date variables in SELECT Statement within SQLPLUS?

Thank you!
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.

Check the NLS_DATE_FORMAT parameter
To make sure of the format always use TO_DATE like this...


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
pavelmedAuthor Commented:
I was able to resolve it by first using to_char() to reformat "mindate" and "maxdate" to DD-MM-YYYY,
and then in the second select statement using to_date() to reformat the values back to the date format.
I am assigning points to sandeshi since his suggestion is close to what I was doing.
Thank you!
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Hi pavelmed,
I'm glad that my answer came close to what you've finally implemented. Just as a gentle reminder, as stated by you above probably you've forgotten to assign the points and close this question.
pavelmedAuthor Commented:
Sorry Sandesh,

I did forgot to assign points.  Doing this now.
Hey! Thanks.
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
Oracle Database

From novice to tech pro — start learning today.