博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oracle Form's Trigger Tutorial With Sample FMB
阅读量:6303 次
发布时间:2019-06-22

本文共 1895 字,大约阅读时间需要 6 分钟。

Created an Oracle Form to handle specific events / triggers like When-New-Form-Instance, Pre-Insert, Post-Insert, Pre-Update, Post-Update, Post-Query and Post-Forms-Commit.

I am doing the following simple tasks on these events to give you an example:

When-New-Form-Instance Trigger

Picking up Oracle Session ID through USERENV function and User to display below the title of the form, the following is the code written:

BEGIN
   SELECT    'ORACLE SESSION ID: '
          || USERENV ('SESSIONID')
          || ' USER NAME: '
          || USER
     INTO :VAL_FORM_INSTANCE
     FROM DUAL;
END;

Post-Query Trigger

Populating the Department Name.

BEGIN
   SELECT department_name
     INTO :scott_emp.dptname
     FROM dept
    WHERE department_id = :scott_emp.deptno;
EXCEPTION
   WHEN OTHERS
   THEN
      NULL;
END;

Pre-Insert Trigger

Checking if the Hiredate is current date or not.

BEGIN
   IF :SCOTT_emp.HIREDATE <> TRUNC (SYSDATE)
   THEN
      :VAL_PRE_INSERT := 'Hire Date must be current date.';
      RAISE form_trigger_failure;
   END IF;
   -- else ok
   :VAL_PRE_INSERT := 'Hire Date is valid.';
END;

Post-Insert Trigger

Counting total number of employees in table.

BEGIN
   SELECT 'Employee Count After: ' || COUNT ( * )
     INTO :val_pOST_insert
     FROM scott_emp;
END;

Pre-Update Trigger

Checking if current day is Sunday then stopping the user the update the record.

BEGIN
   IF TO_CHAR (SYSDATE, 'DAY') = 'SUN'
   THEN
      :VAL_PRE_UPDATE := 'Update is not allowed on Sundays';
      RAISE form_trigger_failure;
   END IF;
   :VAL_PRE_UPDATE := 'Update is allowed today.';
END;

Post-Update Trigger

Just giving a simple message.

BEGIN
   :VAL_POST_UPDATE := 'You updated ' || :scott_emp.ename || '''s record.';
END;

Post-Forms-Commit Trigger

Displaying Date and Time of Last Commit

BEGIN
   :VAL_POST_COMMIT :=
      'Last Commit executed on '
      || TO_CHAR (SYSDATE, 'DD-MON-YYYY HH24:MI:SS');
END;

The following is the screen shot of this form and source code(Table's Script and FMB file) can be download from the following link:

 

 

转载地址:http://ezfxa.baihongyu.com/

你可能感兴趣的文章
那些年我们收藏的网站(1 )
查看>>
mysql里在整个数据库查询某一个字段
查看>>
HAproxy
查看>>
曾经用JavaSE解决的NIT试题
查看>>
win7通过adsl共享上网
查看>>
nginx keepalive-timeout
查看>>
CITRIX NETSCALER 常用的功能
查看>>
mysql HA高可用配置
查看>>
ASIHttpRequest 集成到项目介绍
查看>>
Informatica9.6.1 及sqlserver安装图文指南
查看>>
使用java如何将空间数据,写入sql server数据库,我这里用的是jfinal框架
查看>>
知识点总结
查看>>
三年0故障总结,提升代码质量的秘诀
查看>>
网页中用到的对比原则(一):色彩对比
查看>>
Hibernate(二)
查看>>
在这个领域苹果谷歌都已落后 亚马逊才是真正的王者
查看>>
bboss升级至 v5.0.6.8版本,改善对Elasticsearch SQL 的支持
查看>>
localstorage存储数组解析形式
查看>>
开源许可证教程
查看>>
yum path
查看>>