oracle decode combined with aggregation function bug

Recently, the company's business has asked for a strange demand. In the process of writing sql, a bug in the use of decode and aggregate functions in oracle was found.

 

Let's talk about it:

Create a temporary test table first

create table test (id number,value varchar2(10));

insert into test values(1,0);

insert into test values(2,50);

insert into test values(3,100);

insert into test values(4,200);

 

select a.*,a.rowid from test a;

The query results are as follows:

 Find the maximum value of the value column here, which is undoubtedly 200.

Find the minimum value of the value column, which must be 0.

but:

select max(decode(value,0,null,value)) from test;

the maximum value queried with this sql is indeed 50.

 

select min(decode(value,0,null,value)) from test;



 The minimum value queried with this sql is indeed 100.

It's probably an oracle bug.

It seems that this only happens when a few values ​​are fixed, 0, 50, 100, NULL, decode is used in conjunction with max, min.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326773695&siteId=291194637