Oracle_071_lesson_p5

轉換函數

to_char
to_number
to_date

Oracle_071_lesson_p5

Oracle_071_lesson_p5

Oracle_071_lesson_p5

隱式轉換 fm 去掉前導0
顯式轉換 fx 完全精確匹配纔會成功,否則報錯

NVL(A,B) 若A爲NULL,則輸出B
select last_name,salary,NVL(commission_pct,0),(salary12)+(salary12*NVL(commission_pct,0)) AN_SAL
from employees;

NVL2(A,B,C) 若A爲NULL,則輸出C,若A不爲NULL,則輸出B
select last_name,salary,commission_pct,NVL2(commission_pct,'SAL+COM','SAL') income
from employee where department_id IN (50,80);

NULLIF(A,B) 若A=B,則爲NULL,若A<>B,則輸出A
select first_name,LENGTH(first_name) "expr1",last_name,LENGTH(last_name) "expr2",NULLIF(LENGTH(first_name),LENGTH(last_name)) result
from employees;

COALESCE(A,B,C,.......Z) 從A開始往後判斷是否爲NULL,找到不爲NULL時則輸出值,單最後Z不能設定爲NULL

select last_name,salary,commission_pct,COALESCE((salary+(commission_pct*salary)),salary+2000) "new Salary"
from employees;

條件表達式
CASE
select last_name,job_id,salary,
case job_id when 'IT_PROG' THEN 1.10salary
when 'ST_CLERK' THEN 1.15
salary
when 'SA_REP' THEN 1.20*salary
else salary
end "REVISED_SALARY"
from employees;

DECODE
select last_name,job_id,salary,
DECODE(job_id,'IT_PROG',1.10salary,
'ST_CLERK',1.15
salary,
'SA_REP' ,1.20*salary,
salary)
REVISED_SALARY
from employees;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章