Using the Decode PL/SQL

Posted on 2009-04-29
Last Modified: 2013-12-07
I would like to use the Decode function in my query to do the followingi

if rec_itl_medical.expiration_date < vSysDate then
          vStatusReason := 'EXPIRED';
           vActive := 'INACTIVE';
        vStatusReason := NULL;
        if rec_itl_medical.qualified = 'Y' then
               vActive := 'ACTIVE';
             vActive := 'INACTIVE';  
          end if;  
    end if;
Question by:cookiejar
    LVL 27

    Accepted Solution

    Something like this should do
    select  case when rec_itl_medical.expiration_date < vSysDate then 'EXPIRED' 
            else null end AS vStatusReason,
            case when rec_itl_medical.expiration_date < vSysDate then 'INACTIVE'
            else case when rec_itl_medical.qualified = 'Y' then 'ACTIVE'
                 else 'INACTIVE' end
            end AS vActive 
    from .....

    Open in new window

    LVL 9

    Assisted Solution


    SELECT decode(sign(vSysDate - rec_itl_medical.expiration_date),
             1, 'EXPIRED',
           decode(sign(vSysDate - rec_itl_medical.expiration_date),
             1, 'INACTIVE',
                decode(nvl(rec_itl_medical.qualified, 'N'),
                  'Y', 'ACTIVE',
      INTO vStatusReason, vActive
      FROM DUAL;

    Open in new window


    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    Suggested Solutions

    Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
    Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
    Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
    This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now