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. Python之路-python(堡垒机)

    运维堡垒机开发 前景介绍 到目前为止,很多公司对堡垒机依然不太感冒,其实是没有充分认识到堡垒机在IT管理中的重要作用的,很多人觉得,堡垒机就是跳板机,其实这个认识是不全面的,跳板功能只是堡垒机所具备的 ...

  2. spring session 和 spring security整合

    背景: 我要做的系统前面放置zuul. 使用自己公司提供的单点登录服务.后面的业务应用也是spring boot支撑的rest服务. 目标: 使用spring security管理权限包括权限.用户请 ...

  3. VS2010 LINK1123:failure during conversion to COFF:file invalid or corrupt

    今天用Visual Studio 2010编译一个C工程时突然遇到下面这个编译错误.fatal error LINK1123:failure during conversion to COFF:fil ...

  4. Maven 实战

    http://www.cnblogs.com/chowmin/category/599392.html

  5. 理解水平扩展和垂直扩展 (转载 http://yunjiechao-163-com.iteye.com/blog/2126981)

      当一个开发人员提升计算机系统负荷时,通常会考虑两种方式垂直扩展和水平扩展.选用哪种策略主要依赖于要解决的问题 以及系统资源的限制.在这篇文章中我们将讲述这两种策略并讨论每种策越的优缺点.如果你已经 ...

  6. 用 WEKA 进行数据挖掘,第 1 部分: 简介和回归(转)

    http://www.ibm.com/developerworks/cn/opensource/os-weka1/index.html 简介 什么是 数据挖掘?您会不时地问自己这个问题,因为这个主题越 ...

  7. oracle细节

    1.oracle中NVL的含义: 如果oracle第一个参数为空那么显示第二个参数的值,如果第一个参数的值不为空,则显示第一个参数本来的值. 2.Oracle中in和exists的区别: 1).sel ...

  8. C# 使用BackgroundWorker例子及注意点

    该例子为使用BackgroundWorker在TextBox文本中产生一个10000以内并且能被5整除的数(1秒产生一个) 操作界面可以启动线程,也可以停止线程,界面设计如图: 先贴代码,有注释的地方 ...

  9. paper

    1 IR 小目标检测 “Learning to detect small target A local kernel method” Xie K, Zhou T, Qiao Y, et al. Lea ...

  10. 如何让 XE5 发现你的手机

    首发在 ① FireMonkey[DELPHI XE5]  165232328 欢迎使用 FMX 开发手机程序的高手来访. 1. 手机开启 USB 调试.不用 ROOT.2. 装驱动.(问题就在这里) ...