11:50:08 SQL> select * from t1;         A          B
---------- ----------
         1          1
         1          2
         2          3
         2          4
         3          4已用时间:  00: 00: 00.00
11:50:21 SQL> select case when a=b then 999 else a+b end  from t1;CASEWHENA=BTHEN999ELSEA+BEND
----------------------------
                         999
                           3
                           5
                           6
                           7已用时间:  00: 00: 00.16

解决方案 »

  1.   

    select decode when a=b then a=a else a=a+b end from table
      

  2.   

    同意这个
    select case when a=b then 999 else a+b end  from t1;decode的写法:
    select decode(a,b,999,a+b) from t1
      

  3.   

    错了,如果A,B都是字符型的话,999要写成这样‘999’select case when a=b then ‘999’ else a+b end  from t1;
      

  4.   

    select decode(a,b,a,a+b) from table;
    请参考:
    Examples
    This example decodes the value warehouse_id. If warehouse_id is 1, then the
    function returns ’Southlake’; if warehouse_id is 2, then it returns ’San
    Francisco’; and so forth. If warehouse_id is not 1, 2, 3, or 4, then the function
    returns ’Non-domestic’.
    SELECT product_id,
    DECODE (warehouse_id, 1, ’Southlake’,
    2, ’San Francisco’,
    3, ’New Jersey’,
    4, ’Seattle’,
    ’Non-domestic’)
    quantity_on_hand FROM inventories;