Oracle:decode

1.使用decode判断字符串是否一样
DECODE(value,if 条件1,then 值1,if 条件2,then 值2,…,else 其他值)

Sql测试:
select DECODE(A2,‘2’,‘student’,‘3’,‘teacher’,‘others’) as name from table_20180910 where rownum < 5;

NAME
student
student
student
student

2.使用decode判比较大小
Select decode(sign(var1-var2),1,var1,var2) from dual
Sign()函数根据某个值是0、正数、负数,分别返回0、1、-1;

Sql测试:
select decode(sign(100-110),1,2,3) as c1 from dual

c1
3

Oracle:decode(city,0,‘否’,1,‘是’)
MySQL:case city when 0 then ‘否’ when 1 then ‘是’ end

发布了58 篇原创文章 · 获赞 5 · 访问量 5130

猜你喜欢

转载自blog.csdn.net/weixin_42161670/article/details/97764147