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 it logs the error into a table named error_log, so that a DBA can view all the errors with their execution time, user and program information. See the example below:

On-Error Trigger code:

declare
    vabutton number;
    verrtxt varchar2(80) := error_text;
    verrno number := error_code;
    vdbms number := dbms_error_code;
    verrtype varchar2(20) := error_type;
begin
    if vdbms = -3114 or vdbms = -1017 or vdbms = -3115 or vdbms = -1012 then
   -- logon related errors
    set_alert_property(‘errmes‘, title, ‘App ‘||ltrim(to_char(vdbms)));
    set_alert_property(‘errmes‘, alert_message_text, ‘Logon denied.‘);
    vabutton := show_alert(‘errmes‘);            
    raise form_trigger_failure;
    end if;
    if verrno = 41009 OR VERRNO = 41008 or verrno = 40100 OR VERRNO = 40105 then
    --- ignoring all errors like at first record etc.
    NULL;
    elsif verrno = 40509 then
            insert into error_log (sqno, username, error_msg, error_cd, error_tp, error_dt, LOCATION) values 
      (error_seq.nextval, :MAIN.USERNAME, verrtxt, verrno, verrtype, sysdate, :SYSTEM.CURSOR_BLOCK);
      frmsave;
    set_alert_property(‘errmes‘, title, ‘Info.‘||ltrim(to_char(verrno)));
    set_alert_property(‘errmes‘, alert_message_text, ‘You cannot update records.‘);
    vabutton := show_alert(‘errmes‘);    
    :main.er := :main.er + 1;
    else
        insert into hms.error_log (sqno, username, error_msg, error_cd, error_tp, error_dt, LOCATION) values 
      (hms.error_seq.nextval, :MAIN.USERNAME, verrtxt, verrno, verrtype, sysdate, :SYSTEM.CURSOR_BLOCK);
     --- frmsave is the database procedure to commit explicitly.
    frmsave;
    set_alert_property(‘errmes‘, title, ‘Info.‘||ltrim(to_char(verrno)));
    set_alert_property(‘errmes‘, alert_message_text, verrtxt);
    vabutton := show_alert(‘errmes‘);
    :main.er := :main.er + 1;
    end if;
    exception 
    when form_trigger_failure then
      null;
        when others then
        -- FOR DEBUG NEXT LINE TO KNOW ERROR NUMBER
--    set_alert_property(‘errmes‘, alert_message_text, ‘[‘||TO_CHAR(ERROR_CODE)||‘] ‘||error_text); 
    insert into error_log (sqno, username, error_msg, error_cd, error_tp, error_dt, LOCATION)values 
      (error_seq.nextval, :MAIN.USERNAME, verrtxt, verrno, verrtype, sysdate, :SYSTEM.CURSOR_BLOCK);
      frmsave;
  set_alert_property(‘errmes‘, alert_message_text, error_text);
    vabutton := show_alert(‘errmes‘);
    :main.er := :main.er + 1;
end;

Error_Log Table structure:


1

SQNO

NUMBER(10)

2

USERNAME

VARCHAR2(20 BYTE)

3

ERROR_MSG

VARCHAR2(200 BYTE)

4

ERROR_CD

NUMBER(10)

5

ERROR_TP

VARCHAR2(10 BYTE)

6

ERROR_DT

DATE

7

LOCATION

VARCHAR2(20 BYTE)

See also: Writing On-Error Trigger in Oracle Forms

时间: 2024-08-06 11:57:11

An Example of On-Error Trigger in Oracle Forms的相关文章

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

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

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

How to Log Users Login and Logout Details Through Oracle Forms

Log user's login and logout details in to table through Oracle Forms using POST-LOGON and PRE-LOGOUT triggers to track the user's login and logout activity for auditing purposes. In this example one table and a sequence object is used to log the data

Pre-Update and Pre-Insert Trigger Examples For Oracle Forms

See also: Why And When To Use Pre-Update and Pre-Insert Triggers In Oracle Forms Pre-Update Fires during the Post and CommitTransactions process, before a row is updated in Oracle Forms. It fires once for each record that is marked for update. The fo

Pre-Query trigger in Oracle D2k / Oracle Forms

Pre-Query trigger in Oracle D2k / Oracle Forms DescriptionFires during Execute Query or Count Query processing, just before Form Builder constructs and issuesthe SELECT statement to identify rows that match the query criteria.Definition Level form or

ArcSDE Post失败:"error connecting to oracle: O".

错误:ArcSDE安装后,Post失败 环境:win7 64,oracle10g(32位),arcsde10.0(32位) 表现:"error connecting to oracle: 0". 问题解决 经过反复测试发现问题:安装路径空格问题 在WIN7 64位时,安装arcsde32位不能安装在C:\Program Files这样的有空格的文件夹里. 但是,在WIN7 32位时不存在这个问题,可以安装在C:\Program Files中. 注意1:有人认为以及部分网上资料,WIN7

Java-解决SSH集成时,oracle报错:Error while registering Oracle JDBC Diagnosablility MBean

今天在做项目练习时,在集成SSH后,发现控制台有oracle的报错: Error while registering Oracle JDBC Diagnosability MBean. javax.management.MalformedObjectNameException: Invalid character ' ' in value part of property at javax.management.ObjectName.construct(ObjectName.java:602)