Oracle System Time Acquisition and formatting

Source: Internet
Author: User

Oracle: SYSDATE (): TO_CHAR (SYSDATE (), 'yy/MM/DD HH24: MI: SS) or TO_DATE (SYSDATE (), 'yy/MM/DD HH24: MI: SS) format the number: TO_NUMBER Note: TO_CHAR converts the date or number to the string TO_CHAR (number, 'format') TO_CHAR (salary, '$99,999.99') TO_CHAR (date, 'format') TO_DATE converts the string to the date type TO_DATE (char, 'format') in the database ') TO_NUMBER converts the string to the number TO_NUMBER (char, 'format') and returns the system date. The output is 25-12-09 select sysdate from dual; mi is minute, and the output is 14:23:31 se. Lect to_char (sysdate, 'yyyy-MM-dd HH24: mi: ss') from dual; mm displays the month and outputs 14:12:31 select to_char (sysdate, 'yyyy-MM-dd HH24: mm: ss') from dual; outputs 09-12-25 14:23:31 select to_char (sysdate, 'yy-mm-dd hh24: mi: ss ') from dual Output 2009-12-25 14:23:31 select to_date ('2017-12-25 14:23:31', 'yyyy-mm-dd, hh24: mi: ss ') from dual, if the previous writing: select to_date ('2017-12-25 14:23:31 ', 'yyyy-mm-dd, hh: mi: ss') from dual, then An error is reported because the hour hh is in 12 hexadecimal format and 14 is invalid and cannot be matched. Output $10,000, 00: select to_char (1000000, '$99,999, 99') from dual; Output RMB10, 000,00: select to_char (1000000, 'l99, 999,99') from dual; output 1000000.12: select trunc (to_number ('123. 123 '), 2) from dual; select to_number ('2017. 123 ') from dual; format of conversion: year: y indicates the last digit of the Year, yy indicates the last two digits of the Year, yyy indicates the last three digits of the Year, and yyyy indicates the month in four digits: mm uses two digits to represent the month and mon in short form. For example, January 1, November, nov, and month use the full name. For example, January 1, November, or November represents the dd table of day. The day of the month, the day of the year, the day of the year, the day of the week, short for, such as Friday, fri, day, the day of the week, the full name, such as Friday or Friday indicates hour: hh 2-digit represents 12-digit hour, hh24 2-digit represents 24-hour represents minute: mi 2-digit represents minute represents second: ss 2-digit indicates the second 60-digit indicates the quarter: q 1-digit indicates the quarter (1-4) and ww indicates the week w of the current month. Time range in the 24-hour format: 00: 00: 00-23:59:59 12-hour format: 1: 00: 00-12:59:59 digit format: 9 indicates that a number 0 is forcibly displayed. 0 $ is placed with a $ character L is placed with a floating local currency character. show the decimal point, and display the thousands indicator. Supplement: select sysdate, sysdate-interval '7' MINUTE from dual in the current time minus 7 minutes; current Time minus 7 hours select sysdate-interval '7' hour from dual; current time minus 7 days select sysdate-interval '7' day from dual; current Time minus select sysdate, sysdate-interval '7' month from dual; current time minus 7 years select sy Sdate, sysdate-interval '7' year from dual; Time interval multiplied by a number select sysdate, sysdate-8 * interval '7' hour from dual; meaning: the Dual pseudo-column Dual is an existing table in Oracle and can be read by any user. It is often used in select statement blocks without a target table. Different systems may return different date formats. Returns the user of the current connection: select user from dual;

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.