ORACLE SQL/PL   case statement - using with IN LIST

Posted on 2007-10-11
Last Modified: 2013-12-07
Hi all,
I have writtent he following CASE Statement in the
criteria for DeptID
CASE :1 WHEN '12345'  
THEN   '555111'   END  -- This works and brings back the specified department.
I have tried many ways to add more deparment numbers but I get a an error.
I've tried
CASE :1 WHEN '12345'  
THEN IN ("555111','12345')

also I have tried:
CASE :1 WHEN '12345'  
THEN DEPTID IN ("555111','123456')
The only one that works is when I have only one department number.  Is this because CASE statements bring only bring back 1 result?
Thanks much for your help.

Is there a way for me to list more than one dept number in a Case Statement without have to create multiple Statements?
Question by:syhctl
    LVL 142

    Accepted Solution

    do not use CASE statement...

    WHERE ( :1 = '12345' AND  yourfield IN ("555111','12345'))
    LVL 18

    Expert Comment

    LVL 23

    Assisted Solution

    Try this one:

    CASE :1 WHEN '12345'  
    THEN DEPTID END IN ("555111','123456')

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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.

    Suggested Solutions

    Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious sideā€¦
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the 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

    759 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

    10 Experts available now in Live!

    Get 1:1 Help Now