Wednesday, August 22, 2012

implement IF-THEN-ELSE logic in a SELECT ORACLE statement


Oracle SQL from Oracle 8i support methods of create  IF-THEN-ELSE using CASE SQL .
See example below:


SELECT  CTA.CUSTOMER_TRX_ID ID_FACTURA,CTA.TRX_NUMBER NUMERO_FACTURA,RCTTA.name,

CASE WHEN RCTTA.name='SPA' OR RCTTA.name='RSPA' 
      THEN TO_CHAR(TO_DATE(CTA.TRX_DATE, 'DD/MM/RRRR'), 'DD/MM/RRRR') 
 WHEN RCTTA.name='EXP' OR RCTTA.name='REXP' 
       THEN TO_CHAR(TO_DATE(CTA.TRX_DATE, 'DD/MM/RRRR'), 'MM/DD/RRRR')
ELSE 
        TO_CHAR(TO_DATE(CTA.TRX_DATE, 'DD/MM/RRRR'), 'MM/DD/RRRR')
END AS FECHA_FACTURA

FROM RA_CUSTOMER_TRX_ALL CTA ....




No comments:

Post a Comment