码迷,mamicode.com
首页 > 数据库 > 详细

sql 流程函数

时间:2018-07-15 11:22:02      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:oracle   rac   use   when   The   values   rom   min   table   

create table salary (userid int,salary decimal(9,2));

-- mysql
insert into salary values(1,1000),(2,2000), (3,3000),(4,4000),(5,5000), (1,null),(2,500);
-- oracle
  insert all
    into salary values(1,1000)
    into salary values(2,2000)
    into salary values(3,3000)
    into salary values(4,4000)
    into salary values(5,5000)
    into salary values(1,null)
    into salary values(2,500)
    select * from dual;

-- if(value,t f)
  select salary, if(salary>2000,‘high‘,‘low‘) hl from salary; --  oracke 不支持

-- case when ... then...else...end

  select salary, case when salary<=2000 then ‘low‘ else ‘high‘ end hl from salary;
  select salary, case when salary<=2000 then ‘low‘ when salary is null then ‘low‘ when salary<=4000 then ‘min‘ else ‘high‘ end hl from salary;

-- case ... when ... then...else...end
  select salary, case salary when 1000 then ‘low‘ when 2000 then ‘mid‘ else ‘high‘ end hl from salary;

sql 流程函数

标签:oracle   rac   use   when   The   values   rom   min   table   

原文地址:https://www.cnblogs.com/BaiLaowu/p/9311756.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!