Oracle CASE WHEN LIKE查询

Oracle CASE WHEN的常规用法
SELECT CASE T.PAYCODE
         WHEN '1' THEN
          T.CASH
         WHEN '2' THEN
          T.CREDIT
         ELSE
          T.CASH
       END AS PAYAMOUNT
  FROM PAYMENT T;
--PAYCODE为1查询CASH,为2查询CREDIT,其他查询CASH
  
Oracle CASE WHEN可以与LIKE结合使用
SELECT CASE
         WHEN T.SERIALNO LIKE '1%' THEN
          T.CASH
         WHEN T.SERIALNO LIKE '2%' THEN
          T.CREDIT
         ELSE
          T.CASH
       END AS PAYAMOUNT
  FROM PAYMENT;
--SERIALNO为1开头查询CASH,为2开头查询CREDIT

你可能感兴趣的:(DB)