Decode for Oracle function usage. The DECODE function compares the value with a series of sequence dolls to determine the final returned results. We compared the Oracle function with the switch function and found that they are basically similar. The only difference is that the switch will compare the values with the break after the case.
In the following example, I found it on the Internet)
- 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 11 = 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. The above content is an introduction to the decode of Oracle function usage. I hope you will find some gains.