Oracle Conversion Functions

Source: Internet
Author: User

Examples of conversion functions for Oracle Show

--Automatic type conversionSelect 1+'1'  fromdual;--preceded by a string that is automatically converted to the date typeSelectAdd_months ('January-July on -2017',2) fromdual;--to_number To_char to_dateSelectSysdate fromdual;--Convert a Date function to a string: To_char ()SelectSysdate,to_char (Sysdate) fromdual;--the format of the date you defineSelectSysdate,to_char (Sysdate,'YYYY-MM-DD HH24:MI:ss') fromdual;SelectSysdate,to_char (Sysdate,'YYYY-MM-DD') fromdual;SelectSysdate,to_char (Sysdate,'HH24:MI:ss') fromdual;--convert a number to a string: To_charSelect 123, To_char (123) fromdual;--9 represents a placeholder, and if the number of digits is less than the previous number, it will be displayed #--L represents the local currency symbolSelect 123, To_char (123,'999') fromdual;--To_date Converting a string into a date typeSelectMonths_between (Sysdate,'2017-12-17') fromdual;--to_date () The format of the date must be specifiedSelectMonths_between (Sysdate,to_date ('2017-12-17','YYYY-MM-DD')) fromdual;--To_number string to numeric string must be only numericSelect '123', To_number ('123.000') fromdual;--NVL is equivalent to the conditional operator in Java A?B:C--Check all employees ' names, positions, salaries, commissions and total wagesSelectEname,job,sal,comm,sal+Comm Income fromEMP;SelectENAME,JOB,SAL,NVL (Comm,o) comm,sal+NVL (Comm,0) income fromEMP;--NVL2: There are three parameters, the first parameter is NULL, the value of the third parameter is returned, otherwise the secondSelectENAME,JOB,SAL,COMM,NVL2 (comm,sal+Comm,sal) Income fromEMP;--both data types must be consistentSelectCOMM,NVL (Comm,'No') from;--If the data types are inconsistent, an error occurs. --decode functions like Switch...case ...--search for positions for all employees and display them in ChineseSelect distinctJob fromEMP;SelectDecode (Job,'Clerk','Staff','salesman','Sales Clerk','President','Don't know','MANAGER','Manager','ANALYST','Analyst') asJob fromEmp

Oracle Conversion Functions

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.