Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

sql - Oracle - get current date formatted

I've been wondering - I have a lot of use with sysdate on my system, and when comparing it to my date columns I have to use trunc(sysdate) since the format of sysdate is DD/MM/YYYY HH24:MI:SS .

I looked over the internet for other functions to return current date on format of DD/MM/YYYY but had no luck, current_date , current_timestamp and ETC also gives me the hours format..

I need this for better performance when comparing an indexed date column to the current date.

So , anybody know of a system function that returns the desired format? or a way to bypass it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If your "date" column is of type DATE, then you do not need to be concerned with "format". You need to compare trunc(column_name)to trunc(sysdate). And if that is causing serious performance issues because the use of a function eliminates the use of the index, then create a function-based index. A less elegant solution would be

WHERE mydatecol > trunc(sysdate) AND mydatecol < trunc(sysdate +1)

What you do NOT want to do is confuse the binary concept of DATE with the character string representation of a date. A character string is just a string of characters that you as a human recognize as a data, but to the computer, '2016-02-14' has no more meaning than 'hereisyoursign'.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...