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