Solved

case statement and like operator in pl/sql

Posted on 2008-06-20
4
5,134 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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 shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

623 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