Differences in case and decode usage and Performance Comparison of Oracle Functions

Source: Internet
Author: User
Use case and decode of Oracle functions and compare their performance to achieve logical judgment. Oracle's DECODE function is very powerful. If you use it flexibly, you can avoid multiple scans.

Use case and decode of Oracle functions and compare their performance to achieve logical judgment. Oracle's DECODE function is very powerful. If you use it flexibly, you can avoid multiple scans.

In the Oracle world, you can use:

1) case expression or

2) decode Function

To realize logical judgment. Oracle's DECODE function is very powerful. If you use it flexibly, you can avoid multiple scans to improve query performance. CASE is a syntax provided after 9i. This syntax is more flexible and provides the if then else function.

Case expression

A case expression can be divided into two types: simple and search. A simple case is followed by an expression, for example:

Pay attention to the following points for a simple case:

1) Priority of when search: top to bottom

2) when there are more when, there is only one exit, that is, if one of them meets expr, it will immediately exit the case.

3) return_expr and else_expr cannot be specified as null. Moreover, the Data Types of expr, comparison_expr, and return_expr must be the same.

Search case:

Case when condition THEN return_expr

[WHEN condition THEN return_expr]

...

ELSE else_expr

END

Example:

Decode can violate the 3NF (the row cannot be further divided, the column cannot be further divided, and the column cannot be repeated): The column is repeated.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.