简体   繁体   中英

Dynamic SQL Query To_Date Format Oracle

I am using Oracle SQL Developer.

My tutor has asked us to include Dynamic Queries into our SQL statement.

Part of my query is this:

where booking.date_event != to_date('20140309','yyyymmdd') and booking.occassion_id=2

I have modified the query one step at a time to include the dynamic aspect. So it now looks like this:

where booking.date_event != to_date('20140309','yyyymmdd') and booking.occassion_id='&occassion_id'

This gives me the pop-up box to enter the ID correctly and it works correctly.

However, i now want to do the same for the date. But obviously entering a date in the format 'yyyymmdd' is not very user friendly.

How can i change my query to either allow for various types of date format or to add a message to the pop up box to inform the user to use the correct format? At the moment the pop up box only says "Date_Event" and an input box.

try to_date function. Here is some tips for to_date function.

http://www.dba-oracle.com/f_to_date.htm

SQL Developer is no tool for users. So you don't really have to worry about '20140309' format not being user friendly. For real users you would write a real app that accepts a date (with a calendar popup for instance) and sends it to the database in appropriate format.

However to have it a bit more convenient in SQL Developer, you could use to_date without format. Having set your environment and the database to the same locale, you could simply enter a date in the format you are used to (eg 9.3.13 or 09.03.2013 or March 9, 2013) and it should all work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM