----------////////////////// The generic function ////////////////////////---------------nvl function If exp1 It's empty , Then return to exp2Select nvl(comm,0) From emp--nullif function If exp1 and exp2 equal , Then return to null , Otherwise return to exp1Select nullif(1,2) From dual--nvl2 function If exp1 Not empty , Then return to exp2 , Otherwise return to exp3Select empno,ename,sal,comm,nvl2(comm,sal+comm,sal) total From emp--coalesce function Return when non empty Select empno,ename,sal,comm,coalesce(sal+comm,sal,0) total From emp--case function Select empno,ename,sal,Case deptno When 10 Then ' Finance Department ' When 20 Then ' R & D department ' When 30 Then ' The sales department 'Else ' Unknown Department 'End department From emp;--decode function Select empno,ename,sal,decode(deptno,10,' Finance Department ',20,' R & D department ',30,' The sales department ',' Unknown Department ') department From emp;-- Multi line sub query , The subquery does not return a result Select * From emp Where sal>Any(Select Avg(sal) From emp Group By deptno);Select * From emp Where sal>All(Select Avg(sal) From emp Group By deptno);Select * From emp Where job In (Select job From emp Where ename='MARTIN' Or ename='SMTTH')-- The first way to write a paging query select * from ( select rownum no,e.* from ( select * from emp order by sal Desc ) e where rownum<=5) where no>=3;-- The second way to write paging query select * from ( select rownum no,e.* from ( select * from emp order by sal Desc ) e) where no>=3 and no<=5;-- Randomly return five rows of data Select * From ( Select empno,ename,job From emp Order By dbms_random.value() ) Where Rownum <= 5;Select * From emp Order By sal -- The first letter is capitalized Select initcap(ename) From emp-- Connection string Select concat('hello ','word') From dual-- Intercepting string Select substr(ename,-3,3) From emp-- rounding Select round(789.567,-2) From dual-- Take several numbers directly , Do not round off Select trunc(789.576,-2) From dual-- Hired for a few weeks Select round((Sysdate-hiredate)/7) From emp-- year month Japan Select empno,ename,to_char(hiredate,'yyyy') Year,to_char(hiredate,'mm') months,to_char(hiredate,'dd') Day From emp-- Format to set the time format Select empno,ename,to_char(hiredate,'yyyy-mm-dd') From emp-- Go to zero Select empno,ename,to_char(hiredate,'fmyyyy-mm-dd') From emp-- dollar Select empno,ename,to_char(sal,'$99,999') From emp-- Local Select empno,ename,to_char(sal,'L99,999') From emp-- Annual salary ( Wages + Bonus )×12Select empno,ename,nvl(comm,0),(sal+nvl(comm,0))*12 income From emp-- Bonus is not empty Select Distinct job From emp Where comm Is Not Null-- Employee information hired on the penultimate day of each month Select * From emp Where Last_day(hiredate)-2=hiredate-- The highest 12 Hired years ago , Total months between today and date of employment /12Select * From emp Where months_between(Sysdate,hiredate)/12 > 12-- How many days have you been employed Select ename,round(Sysdate-hiredate) From empSelect * From emp-- Years of service , Monthly limit Select ename,trunc(months_between(Sysdate,hiredate)/12) Year, trunc(Mod(months_between(Sysdate,hiredate),12)) monthsFrom emp
The above code is for reference only
I recommend you to read more about “ oracle sql function ” The article