It can for instance be used to build a decision table. Consider the following decision table:. The column in our table just holds the code instead of the value. If we want to represent the value instead of the code we could write a query like this:. The case statement has two flavors. The simple case and the searched case.
In the simple case the expression is written only once and depending on the result of this expression one of the possible cases is being used. This can be helpful when you need to choose from a set of distinct values. In the searched case every case has its own expression. This can for instance be helpful when using ranges. The else clause is optional. NULL values are one of the most mind-boggling values in the Oracle database. Find out more. Fortnightly newsletters help sharpen your skills and keep you ahead, with articles, ebooks and opinion to keep you informed.
View all articles by Patrick Barel. FROM emp t. WHERE t. NVL expr1 , expr2. NVL2 expr1 , expr2 , expr3. LNNVL condition. FROM emp e. AND e. FROM table ;. ELSE 'Unknown'. END color. Redgate Deploy is the solution to automate database deployments so that software can be delivered more frequently and reliably. From versioning to Continuous integration and repeatable deployments, Redgate Deploy enables Continuous delivery of database changes for SQL Server, Oracle and 18 other databases. Active Oldest Votes.
Alex Zen Alex Zen 7 7 silver badges 9 9 bronze badges. The "searched" CASE expression evaluates much more general logical "conditions", not just equality. This and the slightly different syntax is what Alex demonstrates in this Answer. Add a comment. Punnerud Punnerud 4, 2 2 gold badges 41 41 silver badges 40 40 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog.
Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked Related Hot Network Questions. Question feed.
0コメント