Monday, July 29, 2013

Custom Order in Oracle SQL

  SELECT haou.NAME, haou.TYPE, HR.MEANING
    FROM hr_all_organization_units haou, HR_LOOKUPS HR
   WHERE     TYPE IS NOT NULL
         AND HR.LOOKUP_TYPE = 'ORG_TYPE'
         AND HR.LOOKUP_CODE = HAOU.TYPE
ORDER BY CASE
            WHEN TYPE = 'BG' THEN 1
            WHEN TYPE = 'GR' THEN 2
            WHEN TYPE = 'DE' THEN 3
            WHEN TYPE = 'SE' THEN 4
            WHEN TYPE = 'UN' THEN 5
            ELSE 6
         END


No comments:

Post a Comment