A brief summary of conditional queries on datetime in SQL Server and Oracle summaries _ database other

Source: Internet
Author: User
Tags datetime string format oracle database
First, take a look at SQL Server, before we both select a start time and an end time (in the smallest unit of day) from the foreground user and then query as a condition, if directly through "between StartTime and Endtime" as a condition, Discovery will automatically convert "2009-06-17" to "2009-06-17 00:00:00", so the following query conditions "between ' 2009-06-16 ' and ' 2009-06-17 '", can only get the data of 16th, 17th data can not be obtained, If you want to find out the 17th data, we can do some processing on the user's choice of time: You can add detailed time conditions, such as "Between ' 2009-06-16 00:00:00 ' and ' 2009-06-17 23:59:59 '" Or simply to replace the end time with the date of the next day, but this requires us to do some special processing of the increment date, because we may encounter the choice of the last days of the month, detailed processing here is not to repeat.


Here's what you can do with Oracle database, but if we take the exact time, we need to process Oracle's database time function, which is relatively cumbersome, and it might be more convenient to go directly through the incremental end date, of course, Only the minimum unit of the selected date is "Day". It is also important to note that the date string format adopted in Oracle is not the same as that of SQL Server, typically "May-June-09", which requires us to do intermediate conversions of the time format acquired, otherwise the statement will not execute properly, of course, We can also deal with database functions, but relatively complex.


In fact, sometimes, for many problems, we can take a more formal approach to deal with, but if the scope of the requirements are limited, but can fully meet the requirements of the implementation method, I think it can be bold areas to use, Because the ultimate goal of our programming is: to achieve the goal in the simplest way, everything can not be too rigid, the process is actually to improve our understanding of the project needs, and finally, we need to pay attention to the path we must avoid some of the problems, should not be too careless oh.
Related Article

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.