Related to Oracle Database To_date () and To_char ()

Source: Internet
Author: User

SELECT * from T_a A where A.begintime=to_date (' 2013-1-1 ', ' yyyy-mm-dd ');
And
SELECT * from T_a A where To_char (a.begintime, ' yyyy-mm-dd ') = ' 2013-1-1 ';

The query results are the same.

The difference is that the processing steps of the query are not the same.

SELECT * from T_a A where A.begintime=to_date (' 2013-1-1 ', ' yyyy-mm-dd ');
is to first convert the string ' 2013-1-1 ' to a date format and then to compare it with the database.
If there are 1000 rows of data, then the operation is
1 characters converted to date, 1000 date comparison.

SELECT * from T_a A where To_char (a.begintime, ' yyyy-mm-dd ') = ' 2013-1-1 ';
is to convert the begintime of each row in the database into a character format and then compare it to the database.
If there are 1000 rows of data, then the operation is
1000 times the date is converted to characters, and 1000 string comparisons.
Ask
The second kind of general use under what circumstances ah, seems to affect the performance of the program AH
Chase Answer
So it is generally not recommended to use the second method ah.
Ask
There's always a reason why it's so used.


Transferred from: https://zhidao.baidu.com/question/528644264.html

Related to Oracle Database To_date () and To_char ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.