Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

case statement and like operator in pl/sql

Posted on 2008-06-20
4
Medium Priority
?
5,559 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
  • 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.
Suggested Courses

783 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