日期:2014-05-17  浏览次数:20774 次

求根据订单长度,更新字段值的sql
需求是
更新RECHARGE_NOTE,判断字段flow_code的长度
如果是20位,纯数字,修改pay_kind=2(盛付通)
如果是16位,纯数字,修改pay_kind=1(国付宝)
如果是16位,有字母,修改pay_kind=0(易宝)

------解决方案--------------------
改进了下:

  update RECHARGE_NOTE t
     set t.pay_kind = case
                        when length(t.flow_code) = 20 and
                             REGEXP_LIKE(t.flow_code, '\d{20}') then
                         2
                        when length(t.flow_code) = 16 and
                             REGEXP_LIKE(t.flow_code, '\d{16}') then
                         1
                        when length(t.flow_code) = 16 and
                             REGEXP_LIKE(t.flow_code, '[[:alpha:]]+') then
                         0
                        else
                         t.pay_kind
                      end;