Oracle's to_number, to_char, and to_date usage

Source: Internet
Author: User

Oracle's to_number, to_char, and to_date usage
TO_DATE is to convert the string to the date type conversion function in the database TO_CHAR is to convert the date or number to the string TO_NUMBER to convert the character to the number TO_DATE using the TO_DATE function to convert the character to the date TO_DATE (char, 'format') Example 1: select to_date ('2017-07-01 10:00:00 ', 'yyyy-mm-dd hh24: mi: ss') from dual; select to_date ('2017-07-01 ', 'yyyy-mm-dd hh24: mi') from dual; select to_date ('2017-07-01 10 ', 'yyyy-mm-dd hh24') from dual; select to_date ('2017-07-01 ', 'yyyy-mm-dd') from dual; select to_date ('1970-07 ', 'yyyy-mm') from dual; select to_date ('20140901', 'yyyy') from dual; -- yyyy/yyy/yy represents the 4-digit, 3-digit, and 2-digit year, mm represents the month, and dd represents the day, respectively, hh24/hh12 represents the 24-hour/12-hour system, and mi represents the minute. ss represents the second. Example 2: The czsj in the jmzs table is of the vachar2 type and is converted to the date type: select to_date (czsj, 'yyyy-mm-dd hh24: mi: ss') from jmzs; TO_CHAR use the TO_CHAR function to process the number TO_CHAR (number, 'format') TO_CHAR (salary, '$99,999.99'); Use the TO_CHAR function to process the date TO_CHAR (date, 'format'); Example 1: select To_Char (to_date ('2017-07-01 10:00:00 ', 'yyyy-mm-dd hh24: mi: ss'), 'yyyymmddhhmis') from dual; Example 2: The czsj in Table jmzs is of the vachar2 type, which is first converted to the date type, convert it to char type: select To_Char (to_date (czsj, 'yyyy-mm-dd hh24: mi: ss'), 'yyyymmddhhmiss ') from jmzs; TO_NUMBER use the TO_NUMBER function to convert characters into numbers TO_NUMBER (char, 'format') Example 1: select To_Number (To_Char (to_date ('2017-07-01 10:00:00 ', 'yyyy-mm-dd hh24: mi: ss'), 'yyyymmddhhmis') from dual; Example 2: The czsj in Table jmzs is of the vachar2 type, which is first converted to the date type, convert it to the char type before converting it to the number type: select To_Number (To_Char (to_date (czsj, 'yyyy-mm-dd hh24: mi: ss'), 'yyyymmddhhmiss ')) from jmzs;

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.