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. java关键字之final

    final表示不能修改. final修饰的方法不能被重写, final修饰的类不能被继承并且类里的所有方法都是final,成员变量可以是final或者不是final. final修饰的成员变量不可以改 ...

  2. Java class,Object,Class的区别

    代码: http://www.cnblogs.com/hongdada/p/6060487.html package com.company; public class Main { public s ...

  3. MySQL查询出错提示 --secure-file-priv解决方法

    原文 在某台DB上准备运行一个SQL语句,就是用SELECT INTO OUTFILE把查询结果写入到文件的时候提示以下信息: The MySQL server is running with the ...

  4. DNS缓存

    有DNS的地方,就有缓存. 浏览器.操作系统.Local DNS.根域名服务器,它们都会对DNS结果做一定程度的缓存.本文总结一些常见的浏览器和操作系统的DNS缓存时间. Table of Conte ...

  5. leetcode Super Pow

    题目描述: superPow(int a, int[] b),b是一个int数组,每个元素都是正的个位数,组合起来表示一个正整数,例如b=[1,2,3]表示123,求解a^b mod 1337. 思路 ...

  6. html中input标签的tabindex属性

    当浏览者浏览网站时可以通过按TAB键在网页的链接中依次移动,这是一个相当方便实用的功能.但如果网页中链接太多,恐怕按TAB键就没什么作用了,这时不妨通过改变TAB键移动的顺序来突出重点,在某些重要页面 ...

  7. FileSaver.js ////////////////////zzzzzzzzzzzzzz

    FileSaver.js 实现浏览器端文件保存的 JavaScript 库 查看次数: 758 下载次数: 89 更新时间: 2015-06-05 发布时间: 2015-06-05 收藏 插件信息金币 ...

  8. 云硬盘error、error deleting、deleting状态(数据库基本操作小记)

    起因是发现云硬盘显示删光了,但还是创建不了新的云硬盘,在api节点上用cinder list可以看到已经没有硬盘了,但是创建硬盘时,还是会提示配额满了,这是因为数据库里的记录没有更新,对数据库的操作记 ...

  9. 使用Redux管理你的React应用(转载)

    本文转载自: http://www.cnblogs.com/matthewsun/p/4773646.html

  10. paper 131:【图像算法】图像特征:GLCM【转载】

    转载地址:http://www.cnblogs.com/skyseraph/archive/2011/08/27/2155776.html 一 原理 1 概念:GLCM,即灰度共生矩阵,GLCM是一个 ...