Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Wrong results with group by and regexp_replace

chris227Apr 26 2018 — edited Apr 27 2018

Hi,

i am facing a strange phenomenon with an sql query i can't find any explanation for.

Unfortunately i am not able to construct a test case (yet).

Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production on linux

The structure of the query is like

with strs (

  select

    nr

   ,regexp_replace(some_varchar, 'regexp_that_hits_some_streetnames')  str

   -- regexp_replace is not leading to any null values

   ,some more columns

from a_table

)

, grps as (

  select str

     from strs

   group by str

   having count(distinct nr) > 1

)

   select nr, str, other columns

      from strs s

     where exists (select 1 from grps g where g.str = s.str)

With this is got streetnames that are not in grps as the result.

This is only the case if the regexp is matching data in the table (not necessarily the "wrong" data).

If the regexp matches no data or the data is changed by update in order to not match the regexp the results are correct.

Anyone any idea what i am missing?

Thanks and regards

Chris

This post has been answered by AndrewSayer on Apr 26 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 25 2018
Added on Apr 26 2018
5 comments
502 views