Decode () function usage in oracle/plsql

Source: Internet
Author: User

This article briefly introduces the usage of the decode () function in oracle and illustrates the usage of this function in practical use using examples.

In Oracle/PLSQL, the DECODE function has the IF-THEN-ELSE statement function.

The syntax of the DECODE function is:
Decode (expression, search, result [, search, result]... [, default])

Compare the expression value.
Search is more valuable than expression.
Result is the returned value. If the expression is equal to search.

Default is optional. If no match is found, the default value is returned for decoding. If the default value is omitted, the decoding statement returns null (if no matching is found ).
Undo Modification

Applies:

Oracle 9i, Oracle 10g, Oracle 11g

Instance

SELECT supplier_name,
Decode (supplier_id, 10000, 'ibm ',
10001, 'Microsoft ',
10002, 'hett TT packard ',
'Gateway') result
FROM suppliers;

The preceding decoding statement is equivalent to the following IF-THEN-ELSE statement:

IF supplier_id = 10000 THEN
Result: = 'ibm ';

ELSIF supplier_id = 10001 THEN
Result: = 'Microsoft ';

ELSIF supplier_id = 10002 THEN
Result: = 'hett TT Packard ';

ELSE
Result: = 'Gateway ';

End if;


The DECODE function compares the value of each supplier_id one by one.

 

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.