Define Custom Data Filter Using Pre-Query Trigger In Oracle Forms

Oracle Forms is having its default records filter, which we can use through Enter Query mode to specify some search criteria or to filter records before display, but you can also create your own filter, which can be more user friendly and easy to use.

In this example I have created a form based on SCOTT‘s Emp table, below is the screen shot of this form and I am sharing also the form source code FMB file with Scott.Emp table script which can be downloaded with the following link Prequery_Filter.Zip

Created two drop downs and one text item to specify search criteria and populating these drop downs on When-New-Form-Instance trigger, the following is the code written in it:

DECLARE

rg_name   VARCHAR2 (40) := ‘DYNGRP‘;

rg_id     RecordGroup;

errcode   NUMBER;

BEGIN

/*

** Make sure group doesn‘t already exist

*/

rg_id := FIND_GROUP (rg_name);

/*

** If it exists then delete it first then re-create it.

*/

IF NOT ID_NULL (rg_id)

THEN

DELETE_GROUP (rg_id);

END IF;

rg_id :=

CREATE_GROUP_FROM_QUERY (

rg_name,

‘select DISTINCT job, job job1 from scott_emp order by 1‘);

/*

** Populate the record group

*/

errcode := POPULATE_GROUP (rg_id);

CLEAR_LIST (‘FLTJOB‘);

POPULATE_LIST (‘FLTJOB‘, ‘DYNGRP‘);

------- populate for department

rg_id := FIND_GROUP (rg_name);

/*

** If it exists then delete it first then re-create it.

*/

IF NOT ID_NULL (rg_id)

THEN

DELETE_GROUP (rg_id);

END IF;

rg_id :=

CREATE_GROUP_FROM_QUERY (

rg_name,

‘select DISTINCT TO_CHAR(deptno), TO_CHAR(deptno) deptno1 from scott_emp order by 1‘);

/*

** Populate the record group

*/

errcode := POPULATE_GROUP (rg_id);

CLEAR_LIST (‘FLTDEPT‘);

POPULATE_LIST (‘FLTDEPT‘, ‘DYNGRP‘);

GO_BLOCK (‘SCOTT_EMP‘);

EXECUTE_QUERY;

END;

Then written the Pre-Query on Scott_Emp block to modify the "Where Clause" of that block at run time and following is the code:

DECLARE

VWHERE varchar2(1000) := ‘empno is not null ‘;

begin

-- build where clause

if :fltjob is not null then

vwhere := vwhere || ‘and job = :fltjob ‘;

end if;

if :fltdept is not null then

vwhere := vwhere || ‘and deptno = :fltdept ‘;

end if;

if nvl(:fltsal,0) > 0 then

vwhere := vwhere || ‘and sal >= :fltsal ‘;

end if;

set_block_property(‘scott_emp‘, default_where, vwhere);

end;

Created a Push Button to execute query in Scott_Emp block and following is the code written in When-Button-Pressed trigger:

go_block(‘scott_emp‘);

execute_query;

Note: Run the SQL script first to create the table in your current schema before running the form which I provided in source code Prequery_Filter.zip.

时间: 2024-12-23 06:51:36

Define Custom Data Filter Using Pre-Query Trigger In Oracle Forms的相关文章

An Example of On-Error Trigger in Oracle Forms

I wrote this trigger around 4 years ago to handle errors in an application based on Oracle Forms 6i. This trigger handles all errors with some custom messages for some specific errors and not only this after giving an appropriate message to the user

Writing On-Error Trigger In Oracle Forms

Suppose you want to handle an error in oracle forms and want to display custom error message for that error, but also you want to customize more for a particular error. For example there are many fields in form with required property is set to TRUE f

Learn How To Create Trigger In Oracle Forms

I have written many posts related to triggers in Oracle Forms, I have given examples for Form Level triggers, Data Block Level triggers and Item Level Triggers. And in this tutorial I am just giving the simple tutorial to how to create a trigger in O

Create Custom Modal Dialog Windows For User Input In Oracle Forms

An example is given below to how to create a modal dialog window in Oracle Forms for asking user input and return the value to any text item. The following is the screen shot of this demo and this form could be downloaded from the following link: Cus

Using Post_Query Trigger in Oracle Forms

When a query is open in the block, the Post-Query trigger fires each time Form Builder fetches a record into a block. The trigger fires once for each record placed on the block's list of records. Usage NotesUse a Post-Query trigger to perform the fol

Enter Query Mode Search Tricks Using Enter_Query Built-in in Oracle Forms

In this post you will learn how to specify any condition in enter query mode of Oracle Forms. Whenever Enter_Query command executes Oracle Forms comes into enter query mode and in that mode you can specify some criteria to filter the records and afte

Create Stacked Canvas to Scroll Horizontal Tabular Data Blocks In Oracle Forms

In this tutorial you will learn to create horizontal scrollable tabular or detail data block by using stacked canvas in Oracle Forms. As shown in below picture the first column Empno is fixed and middle columns Ename, Job, Mgr and Hiredate are scroll

Custom Data Service Providers

Custom Data Service Providers Introduction Data Services sits above a Data Service Provider, which is responsible for interacting with the underlying Data Source on behalf of the Data Service. Data Services ships with some internal providers, and mak

Create Data Block Based On From Clause Query In Oracle Forms

Example is given below to create a data block based on From Clause query in Oracle Forms. The following are the steps: Create a data block manually and set the following properties: You can specify different query as per your need. Then create the it