【问题标题】:Oracle Reports Builder - checking if query is emptyOracle Reports Builder - 检查查询是否为空
【发布时间】:2019-02-07 23:15:23
【问题描述】:

我正在使用 Oracle Report Builder 11.1.2.2.0。 我的报告中定义的查询很少,当我的查询之一没有返回任何行时,我想执行一些 pl/sql 代码。

例如:

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

如何查看?

【问题讨论】:

    标签: sql oracle plsql report oraclereports


    【解决方案1】:

    您可以尝试使用exception handling 将您的查询转换为function,例如

    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;
    

    并执行下面的代码

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

    【讨论】:

      【解决方案2】:

      据我所知,没有办法做到这一点 - 不是以简单的方式。您必须运行相同的查询两次:一次显示结果(如果有),另一次检查该查询是否返回了某些内容。

      当然,这意味着它会慢得多(执行两次相同的查询)。

      一种解决方法可能是将数据准备到一个单独的表中(看看你是否可以使用全局临时表)一次,然后

      • 检查它是否包含任何行
      • 只需select * from that_table(没有任何条件,因为您在向其中插入数据时已经这样做了)

      或者,如果您感兴趣的查询既简单又快速,只需在您的 PL/SQL 过程中使用它。您必须在多个地方维护相同的代码。看看你是否可以创建一个返回表的函数——这会简化事情(有点)。

      【讨论】:

        猜你喜欢
        • 2019-07-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-18
        • 2020-08-27
        • 2018-06-13
        • 1970-01-01
        相关资源
        最近更新 更多