Oracle date formatting and the use of extract functions

Source: Internet
Author: User

Due to business needs, these two days in learning Oracle, found in Oracle's date it will give you into a very unaccustomed format, so think about how to get it into adulthood, month, day format to display, check information, look at the document, finally found a solution, in fact, the use of the To_char method.

For example, in Oracle, a table in the date, such as 2017-05-06, the column named Time, after the query found that the return is June-May-17 This format, looking at the thief is not happy, want to turn it into a month and day this format, you can do so,

To_char (Time, ' yyyy-mm-dd ') as time  //In parentheses represents the column name in the table, and the second time indicates that the converted date column name is still time

Now that's the date after the conversion, 2017-05-06

So what does the Extract function do? Extract English means to extract, select, as the name implies, it represents the interception of a particular part from a date type, for example, selecting a year or month or day.

For example, there is a table:

      

Now I'm going to pick all the data from the time of year 2018 in the table mytable, you can do that,

Select Title,play,time from MyTable where extract (year from time) = 2018;
Or:
Select Title,play,to_char (Time, ' yyyy-mm-dd ') as time from myTable where extract (year from time) = 2018

The results are obviously all back (here's just a demo)

Now I want to select all the data from the table MyTable for the month 5 in the time, as follows:

Select Title,play,time from myTable extract (month from time) = 5;
Or:
Select Title,play,to_char (Time, ' yyyy-mm-dd ') as time from myTable where extract (month from time) = 5

  

From table MyTable, select all data with date 6 in time as follows:

Select Title,play,time from MyTable extract (day from time) = 6;
Or:
Slect Title,play,to_char (Time, ' yyyy-mm-dd ') as time from myTable where extract (day from time) = 6;

  

The syntax is as follows: Extract (Year | Month| Day | Hour| Minute| second from column_name) = value

Oracle date formatting and the use of extract functions

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.