Solved

case statement and like operator in pl/sql

Posted on 2008-06-20
4
4,898 Views
Last Modified: 2013-12-19
hai !
    the code segment is as follows:

DECLARE
   x   VARCHAR2 (20) := 'bull dog';
   y   VARCHAR2 (20);
BEGIN
   y := CASE x
          WHEN  x 'cat%'
             THEN 'good'
          WHEN '%dog'
             THEN 'too good'
          else
             'bad'
       END;
   DBMS_OUTPUT.put_line (y);
END;
/

but this is now working ' % ' .......wild card.  How to implement this ?
0
Comment
Question by:vishali_vishu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Author Comment

by:vishali_vishu
ID: 21831481
but this is not working ' % ' .......wild card.  

How to implement this ? I mean the wild cards with in case...when statements ?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21831618
that's because CASE WHEN is using = and not LIKE
DECLARE
   x   VARCHAR2 (20) := 'bull dog';
   y   VARCHAR2 (20);
BEGIN
   y := CASE WHEN  x  LIKE 'cat%'
             THEN 'good'
          WHEN x LIKE '%dog'
             THEN 'too good'
          else
             'bad'
       END;
   DBMS_OUTPUT.put_line (y);
END;
/

Open in new window

0
 
LVL 1

Author Comment

by:vishali_vishu
ID: 21831672
angelIII:

I tried that way and it is working.

can't i do some change to my above code to reflect the wildcards ?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21831722
as I said:
CASE x WHEN y
will use = and not LIKE. ie would be the same as
CASE WHEN x = y

if you want to use wildcards, it has to be like this:
CASE WHEN x LIKE y
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

726 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