ORACLE simple functions (TWO)

Source: Internet
Author: User

ORACLE simple function (TWO) 1) date function: 1) sysdate function: This function uses the time zone of the database and returns the date value: eg:

[SQL] SYS @ orcl # select sysdate from dual; SYSDATE -------------- 08-4 month-13 SYS @ orcl #2) months_between () function this function returns two date months with a time difference. Eg: [SQL] SYS @ orcl # select months_between (to_date ('2017-02-03 ', 'yyyy-mm-dd'), to_date ('2017-02-03 ', 2 'yyyy-mm-dd') from dual; MONTHS_BETWEEN (TO_DATE ('2017-02-03 ', 'yyyy-MM-DD'), TO_DATE ('2017-02-03 ', 'yyyy-MM-Example-12 SYS @ orcl # select months_between (to_date ('2017-02-03 ', 'yyyy-mm-dd'), to_date ('2017-02-03 ', 2 'yyyy-mm-dd') month S_between from dual; MONTHS_BETWEEN -------------- 12 3) add_months () function this function adds a month after the specified x month and obtains a date value. Eg: [SQL] SYS @ orcl # select add_months (to_date ('2017-02-03 ', 'yyyy-mm-dd'), 2) add_months from dual; ADD_MONTHS -------------- month-12 SYS @ orcl # select add_months (to_date ('2017-02-03 ', 'yyyy-mm-dd'),-2) add_months from dual; ADD_MONTHS -------------- month 03-12-11 SYS @ orcl #4) next_day () function this function indicates the time value for the first occurrence of day y in a week after the date in x: eg: [SQL] SYS @ orcl # select next_day (to_date ('2017-04-08 ', 'yyyy-mm-dd'), 2) next_day from dual; NEXT_DAY -------------- 15-4 month-13 SYS @ orcl #5) last_day () function this function returns the date of the last day of the month that contains the date parameter x: eg: [SQL] SYS @ orcl # select last_day (to_date ('2017-04-08 ', 'yyyy-mm-dd') last_day from dual; LAST_DAY ------------ 30-4 month-13 SYS @ orcl #6) round () function this function is used to round x. By default, x is the last day, if another date is specified later, such as yyyy, the first day of the last year, for example, [SQL] SYS @ orcl # select round (to_date ('2017-04-08 ', 'yyyy-mm-dd') round from dual; ROUND -------------- month 08-4-13 SYS @ orcl # select round (to_date ('2017-04-08 12:23:23 ', 'yyyy-mm-dd hh24: mi: ss') round from dual; ROUND -------------- month 09-4-13 SYS @ orcl # select round (to_date ('2017-04-08 ', 'yyyy-mm-dd'), 'yyyy') from dual; ROUND (TO_DATE (------------ 01-1 month-13 SYS @ orcl #7) trunc () the function is used for the phase of x date. By default, the start time of the day is truncated. You can specify y at the end, and you can cut off the first day of the year, the first day of the month. For example: [SQL] SYS @ orcl # select trunc (to_date ('2017-04-08 23:23:12 ', 'yyyy-mm-dd hh24: mi: ss') trunc from dual; TRUNC -------------- month-13 SYS @ orcl # select trunc (to_date ('2017-04-08 ', 'yyyy-mm-dd'), 'mm') trunc from dual; TRUNC -------------- month 01-4-13 SYS @ orcl #

 


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.