Oracle's statement __oracle for time range comparisons

Source: Internet
Author: User

There are many ways in which time can be stored in a database, but it is mainly date-oriented, with Oracle as an example

Typically write a time condition directly in a database statement for example: c_datetime<= ' 2014-08-06 ' or between time1 and time2 error

The more classic error is ora-01861:literal does not match format string

The text does not match the format string

A multiple string is required to convert at this time:

To_date (' time1 ', ' yyyy-mm-dd hh24:mi:ss ')

In the concrete time range statement splicing, the general logic is that if the user sets the start time/end time, the logical limit of the stitching start time \ End time in the query statement

SQL is a query statement

if (begintime. =null) {
  SQL =sql + "and ps.cost_datetime>=to_date (' + bgdate + 00:00:00 ', ' yyyy-mm-dd hh24:mi:ss ')";  PS as a table abbreviation
}
if (endtime!=null) {
  sql = sql + "and ps.cost_datetime<=to_date (' + eddate + 23:59:59 ', ' yyyy-mm-dd hh24:mi:ss ')"; PS as a table abbreviation
}

Here you need to see that the general time range includes the same day, so start time starts with 00:00:00, end time ends with 23:59:59

This allows you to query for a time range comparison

General query also need paging display, page display will generally query two times, once for the query to meet the criteria of the number of, once for each specific record

If a time limit is added, add the time constraint to the statement in the number of query bars

For specific paging statements, refer to the previous article


Specific time date range query can refer to http://www.2cto.com/database/201205/132096.html

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.