Oracle中decode的使简单例子

decode(字段,表达式1,表达式2,表达式。。。)
当,字段的值为 表达式1时返回表达式2,以此类推。
例子1:
select decode(opertype,1,'A',2,'B',3,'C','hh') from zm_corp_record
opertype等于1时 返回A


不等于1、2、3时 ,返回hh

例子2:
SELECT ename,comm, DECODE(comm,null, 0) aa FROM emp;
comm为空时,返回0,否则返回空;


例子3:
表table_subject,有subject_name列。要求按照:语、数、外的顺序进行排序。  select * from table_subject order by decode(subject_name, '语文', 1, '数学', 2, , '外语',3)

猜你喜欢

转载自z-kanhai.iteye.com/blog/1550535