An explanation of the use of Oracle decode functions

Source: Internet
Author: User
Oracle decode functions

1. Compare size
Select decode (sign (variable 1-variable 2), 1, variable 1, variable 2) from dual; --Take a smaller value
The sign () function returns 0, 1, 1, depending on whether a value is 0, positive, or negative.
For example:
Variable 1=10, variable 2=20
SIGN (variable 1-variable 2) returns the -1,decode decoding result as "Variable 1", which achieves the purpose of taking a smaller value.
2, this function is used in the SQL statement, the function is described as follows:
The Decode function is similar to a series of nested if-then-else statements.
Base_exp and Compare1,compare2 and so on are compared in turn.
If the base_exp and the compare are matched, the corresponding value of I is returned.
If the base_exp does not match any of the compare values, the default is returned.
Each compare value is evaluated sequentially, and if a match is found, the remaining compare values (if any) are no longer evaluated.
A null base_exp is considered equivalent to the null compare value.
If required, each compare value is converted to the same data type sing Woo the first compare value, which is also the type of the return value.
Integrated 2:decode (V1,1,A,2,B,C)
If V1=1 then shows a = 2 show b other show C .....

An explanation of the use of Oracle decode functions

Related Article

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.