sqloracle-databaseplsqlreportoraclereports

Oracle Reports Builder - checking if query is empty


I'm using Oracle Report Builder 11.1.2.2.0. I have few queries defined in my report and I want to execute some pl/sql code when there are no rows returned from one of my queries.

So for example:

if (query returned no rows) then
    do_something();
end if;

How can I check it?


Solution

  • You can try to convert your query to a function with exception handling such as

    create of replace function get_color( i_color_id color_palette.id%type ) 
                            return color_palette.fg_color%type is    
      o_color  color_palette.fg_color%type;
    begin
      select fg_color
        into o_color
        from color_palette
       where id = i_color_id;
      return o_color;
     exception when no_data_found then return null;
    end;
    

    and execute the code below

    if ( get_color(:id) is null ) then
        paint_it_to_black();
    end if;