Decode for Oracle function usage

Source: Internet
Author: User
Oracle Database: the DECODE function compares the value with a series of sequence dolls to determine the final returned results. The ordinal even is in pairs.

Oracle Database: the DECODE function compares the value with a series of sequence dolls to determine the final returned results. The ordinal even is in pairs.

Oracle Database:

The DECODE function compares the value with a series of sequence dolls to determine the final return result. We compare this function with the switch, and we find that they are basically similar. The only difference is that the values to be compared by the switch are added with break after the case.

Take the following example: (I found it online)

SELECT id,

DECODE (flag, 'y', 'yes', 'n', 'No', NULL, 'none', 'yes ')

FROM t_test;

If the flag field of t_test is Y, Yes is returned. If it is N, No is returned. If it is NULL, None is returned. Yes is returned by default.

Let's take a look at my problems:

SELECT a. id,

A. user_name,

A. oper_time time2,

A. oper_type,

A. description,

A. oper_flag,

Decode (a. oper_flag, '1', 'successfully', 'failed') oper_flag,

A. ip,

B. true_name

FROM SEC_LOG_OPERATION

Left join sec_user B on a. user_name = B. user_name

Where 1 = 1

Order by oper_time desc

The original red lines are: decode (a. oper_flag, 1, 'success', 'failed ')

I will report an error during the query, because the oper_flag field contains non-numeric data, that is, this field not only has 1, 0, but also "failed". This data! = Character. So we can process 1 as a character.

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.