oracle decode函数使用方法

 时间:2024-11-19 09:50:14

1、用法一: 使用decode()判断字符串是否一样decode(value, if 条件1,then 值1,if 条件2,then 值2,...,else 其他值)Sql测试:select aac001,decode(aac001,'0000000001','张三','0000000002','李四','others') as name from ac01 where rownum<=1;输出结果:0000000002,李四

2、用法二: 使用decode()比较大小Select decode(sign(var1-var2),1荑樊综鲶,var1,var2) from dual;(注释: sign()函数根据某个值是0、正数、负数,分别返回0、1、-1)Sql测试:Select decode(sign(100-90),1,100,90) from dual;输出结果 :100解释: 100-90=10>0则sign()函数返回1,decode()函数取值var1为100Sql测试:Select decode(sign(100-90),-1,100,90) from dual;输出结果:90100-90=10>0则sign()返回1,decode()函数取值var2为90

3、用法三: 使用decode()函数分段假设工资大于10000为高薪,工资介于5000到10000为中等,工资小于5000位低薪Sql测试:Select ename,sal,decode(sign(sal-10000),1,'高薪',0,'高薪',-1,decode(sign(sal-5000),1'中等',0,'中等',-1,'低薪'))) from ac01;输出结果:李明 12000 高薪张三 5000 中等王五 3000 低薪

  • java如何判断数组中的元素全部为空?
  • Win 10如何查看当前系统可用的功能和功能状态?
  • win10怎么安装svn?win10系统下安装配置svn方法
  • notepad++开启收缩编辑代码按钮
  • Windows环境下查看软件的安装路径
  • 热门搜索
    重庆有什么旅游景点 江西赣州旅游景点 云南旅游信息网 邵阳旅游景点大全 顺德旅游景点 德国旅游买什么 四川有哪些旅游景点 呼伦贝尔旅游地图 春秋航空旅游网 南京市旅游地图