oracle流程控制

来源:互联网 发布:人人宽客量化交易源码 编辑:程序博客网 时间:2024/06/11 13:19

1 case-when-then-else-end

--创建测试表,插入测试数据create table test(    c1 varchar(50),    c2 varchar(50));insert into test values('1', 'a');insert into test values('2', 'b');insert into test values('3', 'c');insert into test values('4', 'd');insert into test values('5', 'e');--case后直接列名,相当于等值判定。 如果注释掉else,可运行,对应的值为nullselect     case c1        when '1' then 'x'        when '2' then 'y'        else 'z'    end gggfrom    test;--case后没有直接列名,可以做其他条件判断select     case        when c1 < '2' then 'x'        when c1 > '3' then 'y'        else 'z'    end gggfrom    test;--语法和上面是一样的update test set c1 =     case c1        when '3' then 'c'        when '4' then 'd'        else c1    end where c1 in ('3','4','5');