posted 19 years ago
Paul has outlined the best way of doing it; here are 2 alternate not-totally-evil ways of doing it.
Approach 1:
Approach 2:
The primary reason these are not the best ways is that they push work (parseing the date String into a date object) down to the database that can be done at a higher level; in most n-tiered designs, the deeper resources are more expensive and should not be consumed when it's avoidable.
Approach 2 is also ungood because the alter session statements both require additional trips to the database and they're not ignorable in terms of database performance.
As I said, Paul's approach is the best way, generally. I bother to list these because:
a) there's the rare time such as a one-shot program when you just don't care about the differences and one of these is going to be simpler to get the job done.
b) they illustrate other aspects of Oracle that beginning programmers are often not aware of: built-in functions, implicit conversions (almost always a bad thing), "alter session", etc...