select with condition oracle

I have a VARCHAR which value aaa or bbb let say depend on this I have to make

  SELECT x FROM y WHERE y AND som = 1 

or

  SELECT x FROM y WHERE y AND som = 2

I there any way to make this like

SELECT i AS j,
case xxx
      when z then som1
      else som2
  end as ABC  
FROM ...

//EDIT

I want make something like this (lets say its pseudocode ;) )

variable VARCHAR;

SELECT id FROM table WHERE age =
CASE variable
WHEN 'aaa' THEN 21
ELSE 'bbb' THEN 99
END

Answers


You could use a CASE statement

SELECT id
  FROM table
 WHERE age = (CASE WHEN variable = 'aaa' 
                   THEN 21
                   WHEN variable = 'bbb'
                   THEN 99
                   ELSE null
                END)

However, it may be more efficient and easier to read to just do an OR

SELECT id
  FROM table
 WHERE (variable = 'aaa' AND age = 21)
    OR (variable = 'bbb' AND age = 99)

Need Your Help

Foundation datepicker restricted date

javascript jquery datepicker zurb-foundation

Hi guys i am using the foundation datepicker this one below:

How do I programmatically Unblock (IE feature) a file?

powershell cmd wsh windows-security

I like this feature, but in the current build of Windows, clicking the 'Unblock' button and clicking 'Apply' does absolutely nothing. This can cause issues - some files won't run properly.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.