I'm trying to check whether a list of items contain specific number in the condition part of a case statement in Oracle 10g. I get ORA-00936: missing expression
error though. I'm trying to do something like the following:
Select case 'some_column_data'
when in (1,2,3) then 'do_something'
else 'do_something_else' end;
So, is there any way to accomplish what I'm intended to do, or checking whether value is in list iteratively in different when
statements is the only solution?
The case statement in SQL returns a value on a specified condition. We can use a Case statement in select queries along with Where, Order By, and Group By clause. It can be used in the Insert statement as well.
A subquery in the ELSE clause works the same way as a subquery in the THEN clause. We use a passthru predicate to evaluate the subquery conditionally. Similarly, a CASE expression with multiple WHEN clauses with subqueries in each THEN clause also works the same way.
CASE statement in SQL and aggregate functions Aggregate functions in SQL Server perform calculations and return a single value. Examples of aggregate functions are MIN, MAX, COUNT, ABG and CHECKSUM. For this purpose, we use the COUNT aggregate function in SQL Server.
Another way to use the Case Statement is within the WHERE clause. There, it may be utilized to alter the data fetched by a query based on a condition. Within that context, the Case Statement is ideally suited to both static queries, as well as dynamic ones, such as those that you would find inside a stored procedure.
How about using a "Searched CASE expression"
CASE WHEN 'some_column_data' IN (1,2,3)
THEN 'do_something'
ELSE 'do_something_else'
END
See here and here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With