Obtaining Query Count Without executing a Query in Oracle D2k

Obtaining a count of records that will be retrieved by EXECUTE_QUERY before actually performing it in a database block is especially useful when the requirement is to prevent navigation to a block when query hits are zero. A typical scenario of such a situation is when the detail block records exist on a separate canvas not visible on Form startup and the user is required to click a Details button to see them. Giving an alert message such as No Details exist when the user clicks the Details button is more meaningful than displaying a blank details screen, when no details exist for the chosen parent record.
The technique given here avoids two performance issues. First, you do not want to perform a SELECT COUNT(*) from the corresponding base table mainly for performance reasons. Second, using :SYSTEM.LAST_QUERY and executing it dynamically using DBMS_SQL cause a bottleneck by executing the query on the server side explicitly, thus involving more trips.
The solution is to do a COUNT_QUERY and get the QUERY_HITS for the corresponding block immediately following the COUNT_QUERY. The following function does the job:
 
FUNCTION query_count (p_block_name VARCHAR2) RETURN NUMBER

IS

cnt NUMBER;

BEGIN

GO_BLOCK(p_block_name);

COUNT_QUERY;

cnt := GET_BLOCK_PROPERTY(p_block_name, QUERY_HITS);

IF FORM_SUCCESS THEN

    RETURN (cnt);

ELSE

     MESSAGE('Error in getting Query Hits for block '||:SYSTEM.CURRENT_BLOCK);

     RAISE FORM_TRIGGER_FAILURE;

END IF;

END;
The preceding function can be called in the appropriate trigger, such as WHEN-BUTTEN-PRESSED, to achieve the desired functionality.
The following WHEN-BUTTON-PRESSED trigger is defined for the Details button. It initially invokes the above query_count function to obtain the count of detail records for a particular master record. If this count is zero it throws an alert to indicate No Details exist. Otherwise, control navigates to the detail block and does an EXECUTE_QUERY.
 
WHEN-BUTTON-PRESSED trigger of 'Details'button

DECLARE

   v_cnt NUMBER;

BEGIN

   v_cnt := query_count(<detail block name>);

   IF (v_cnt = 0) THEN

     p_show_alert('No Details exist.');

   ELSE

     GO_BLOCK(<detail block name>);

     EXECUTE_QUERY;

   END IF;

END;
This technique involves two tasks:
  • COUNT_QUERY is necessary to initiate the QUERY_HITS property of the block and should be immediately before the GET_BLOCK_PROPERTY statement.
  • Oracle Forms displays the message FRM-40355: Query will display 0 records when the query hits are zero as obtained by a call to COUNT_QUERY. This should be suppressed in an ON-MESSAGE trigger by using the following code:
     
    if message_type = 'FRM'and message_code = 40355 then
    
       null;
    
    else
    
      message(message_type||'-'||to_char(message_code)||': '||message_text);
    
    end if; 

Obtaining Query Count Without executing a Query in Oracle D2k的更多相关文章

  1. java.sql.SQLException: Column count doesn't match value count at row 1 Query: insert into category values(null,?,?,?) Parameters: [1111111, 1111, 软件]

    java.sql.SQLException 问题: java.sql.SQLException: Column count doesn't match value count at row 1 Que ...

  2. Elasticsearch由浅入深(九)搜索引擎:query DSL、filter与query、query搜索实战

    search api的基本语法 语法概要: GET /_search {} GET /index1,index2/type1,type2/_search {} GET /_search { , } h ...

  3. SpringData系列四 @Query注解及@Modifying注解@Query注解及@Modifying注解

    @Query注解查询适用于所查询的数据无法通过关键字查询得到结果的查询.这种查询可以摆脱像关键字查询那样的约束,将查询直接在相应的接口方法中声明,结构更为清晰,这是Spring Data的特有实现. ...

  4. FunDA(1)- Query Result Row:强类型Query结果行

    FunDA的特点之一是以数据流方式提供逐行数据操作支持.这项功能解决了FRM如Slick数据操作以SQL批次模式为主所产生的问题.为了实现安全高效的数据行操作,我们必须把FRM产生的Query结果集转 ...

  5. 【Lucene4.8教程之六】QueryParser与Query子类:如何生成Query对象

    一.概述 1.对于一个搜索而言,其核心语句为: searcher.search(query, 10); 此时,其最重要的参数为一个Qeury对象.构造一个Query对象有2种方法: (1)使用Quer ...

  6. Elasticsearch Query DSL 整理总结(三)—— Match Phrase Query 和 Match Phrase Prefix Query

    目录 引言 Match Phase Query slop 参数 analyzer 参数 zero terms query Match Phrase 前缀查询 max_expansions 小结 参考文 ...

  7. 【Lucene4.8教程之六】QueryParser与Query子类:怎样生成Query对象

    版权声明:本文为博主原创文章.转载请注明来自http://blog.csdn.net/jediael_lu/ https://blog.csdn.net/jediael_lu/article/deta ...

  8. LINQ Query Expressions

    https://msdn.microsoft.com/en-us/library/bb397676(v=vs.100).aspx Language-Integrated Query (LINQ) is ...

  9. WebForm控件Repeater

    我们会发现用拼接字符串来显示一个查询非常的麻烦,有一个控件Repeater帮助你,省去写Foreach LinQ to SQL类 函数类: using System; using System.Col ...

随机推荐

  1. iOS控件之UIResponder类

    iOS控件之UIResponder类 在iOS中UIResponder类是专门用来响应用户的操作处理各种事件的,我们知道UIApplication.UIView.UIViewController这几个 ...

  2. C#正则表达式判断输入日期格式是否正确

      /// <summary>        /// 是否为日期型字符串        /// </summary>        /// <param name=&qu ...

  3. ZooKeeper的Znode剖析

    在ZooKeeper中,节点也称为znode.由于对于程序员来说,对zk的操作主要是对znode的操作,因此,有必要对znode进行深入的了解. ZooKeeper采用了类似文件系统的的数据模型,其节 ...

  4. Flipboard-BottomSheetlayout 源码分析

    BottomSheetLayout BottomSheet:Google在API 23中已经加入了这样的一个控件. BottomSheet介绍: BottomSheet是一个可以从底部飞入和飞出的An ...

  5. 用node-inspector调试Node.js(转自NOANYLOVE'S BLOG)

    原文地址:http://www.noanylove.com/2011/12/node-the-inspector-debugging-node-js/ 用node-inspector调试Node.js ...

  6. ios safari 标签发送到桌面自定义图标方法

    iphone 修改safari 发送到桌面图标 试了几次,总结如下: 1.全屏方法 <meta name="viewport" content="width=dev ...

  7. CF 484E - Sign on Fence

    E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...

  8. 2015最新德淘W家(Windeln.de)新人优惠码wcode0520,赠1000积分,可抵10欧元

    德淘W家(Windeln.de)网址:www.windeln.de 德淘W家(Windeln.de)的新人优惠码wcode0520 第一次购物结账时输入wcode0520,提交订单,1000积分划入你 ...

  9. QT 网络编程

    #include "networkinformation.h" #include "ui_networkinformation.h" networkinform ...

  10. Java面试宝典系列之基础排序算法

    本文就是介绍一些常见的排序算法.排序是一个非常常见的应用场景,很多时候,我们需要根据自己需要排序的数据类型,来自定义排序算法,但是,在这里,我们只介绍这些基础排序算法,包括:插入排序.选择排序.冒泡排 ...