CoinHive

Tuesday, January 2, 2018

ORA-01427: single-row subquery returns more than one row... but not consistently?

Today we had an issue with saved reports. A clients application has a page with an interactive report based on a view. The source of this report is fairly simple:
select * from some_view; 
What could go wrong right? For one thing, some of the saved reports were throwing an ORA-01427 error and some were not. Even worse, the view did not have any errors and running the query in SQLDeveloper did not result in errors.

Eventually we found the problem. SQLDeveloper shows the first 50 records. It's very possible that an error takes place in a result set which is not shown. In our case the view was something like:

select p.last_name
     , p.first_name
     , p.date_of_birth
     , p.city
     , (select c.country
          from cities c
         where c.city_name = p.city
        ) country
  from persons p; 

So I guess the lesson learned is, that when you have select statements in the select part of your query, you should make sure to return all rows when debugging.

Oooorrrr... like my mentor Frank would say: "Don't put a select in the select part of your query!".

No comments:

Post a Comment