Obtaining Query Count Without executing a Query in Oracle D2k

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; 
时间: 2024-10-27 13:48:48

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

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

对于一个搜索而言,其核心语句为: searcher.search(query, 10); 此时,其最重要的参数为一个Qeury对象.构造一个Query对象有2种方法:[均以在contents域搜索java关键词为例] (1)使用Query的子类,如BooleanQuery, ConstantScoreQuery, DisjunctionMaxQuery, FilteredQuery, MatchAllDocsQuery, MultiPhraseQuery, MultiTermQuery, Phr

ElasticSearch search api的基础语法+Query DSL搜索+filter与query对比+组合查询+定位不合法的搜索

一. search api的基础语法 1.search语法 GET /search{} GET /index1,index2/type1,type2/search{} GET /_search{ "from": 0, "size": 10} 2.http协议中get是否可以带上request body HTTP协议,一般不允许get请求带上request body,但是因为get更加适合描述查询数据的操作,因此还是这么用了 GET /_search?from=0&a

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

@Query注解查询适用于所查询的数据无法通过关键字查询得到结果的查询.这种查询可以摆脱像关键字查询那样的约束,将查询直接在相应的接口方法中声明,结构更为清晰,这是Spring Data的特有实现. 索引参数与命名参数 1.索引参数如下所示,索引值从1开始,查询中"?X"个数需要与方法定义的参数个数相一致,并且顺序也要一致. 1 @Query("SELECT p FROM Person p WHERE p.lastName = ?1 AND p.email = ?2"

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

目录 引言 Match Phase Query slop 参数 analyzer 参数 zero terms query Match Phrase 前缀查询 max_expansions 小结 参考文档 系列文章列表 Query DSL Java Rest Client API 引言 今天再读庄子的<逍遥游>,其中鲲鹏之扶摇直上九万里之气势,蜩(tiao)与学鸠之渺小之对比,令人印象深刻,并对鲲鹏之志心生向往.而郭象在注<庄子>卷中却说,"苟足于其性,则虽大鹏无以自贵于小

Mongodb中数据聚合之基本聚合函数count、distinct、group

在之前的文章<Mongodb中数据聚合之MapReduce>中,我们提到过Mongodb中进行数据聚合操作的一种方式--MapReduce,但是在大多数日常使用过程中,我们并不需要使用MapReduce来进行操作,不然有点杀鸡用牛刀的感觉,在这边文章中,我们就简单说说用自带的聚合函数进行数据聚合操作的实现. Mongodb中自带的基本聚合函数有三种:count.distinct和group.下面我们分别来讲述一下这三个基本聚合函数. (1)count 作用:简单统计集合中符合某种条件的文档数量

webform之session传值(临时数据的存储)与扩展属性 --(购物车练习)

页面传值:1.QueryString传值在源页面写:Response.Redirect("Main.aspx?uid="+uid+"&pwd="+pwd);在目标页面:Request["uid"].ToString();2.Session *****特点:可以存任何东西,每个用户都会生成一个特定的Session,Session是存储在服务中的,一般默认存储20分钟,20分钟之后过期用法:在登录页面:Session["uid&qu

20151223:Web:审核:登陆

aspx代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DengLu.aspx.cs" Inherits="DengLu" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="serve

webform--常用的控件

一.简单控件 1.Lable——标签:在网页中呈现出来的时候会变成span标签 属性:Text——标签上的文字  BackColor,ForeColor——背景色,前景色 Font——字体 Bold-加粗  Italic-倾斜  UnderLine-下划线     OverLine 上划线     StrikeOut 删除线  Name - 字体名  Size - 字体的大小 BorderColor——边框颜色 BorderWidth-边框粗细 BorderStyle - 边框样式 Height

用日历存储信息

日历显示主界面 <body> <form id="form1" runat="server"> <div> <asp:Calendar ID="Calendar1" runat="server" CellPadding="0" FirstDayOfWeek="Sunday" NextMonthText="下一月" OnDayR