Oracle APEX - 数据库触发器中的 If 语句
好的。因此,我知道如何创建一个触发器,当对表 A 执行操作时对表 B 进行更改。这相对简单,而且我很乐意这样做。我无法做的是创建一个包含 if 语句的触发器,以便在满足某些条件时执行它。
示例:
表A&表B是相关的。表A包含有关当前正在处理的文档的数据,这些文档由唯一的处理代码标识。表 B 包含有关最终确定和发布的文档的数据,这些文档由出版物 ID 标识。表A和表B是相关的,因为一个文档可能会经历多次修订,因此它可能会在表A中出现多次(唯一的处理代码但相同的出版物ID),而仍然只在表B中出现一次。无论经过多少次修订,出版物 ID 在文档的整个生命周期中都保持不变。
表 A 通过输入表格填写,人们可以在其中提交有关他们希望我们处理的文件的请求。他们可以选择处理新文档,或者是否想要修改表 B 中已有的当前文档。这是通过单选组(新建、修订等...)完成的。如果选择“修订版”,则会出现一个选择列表框,其中填充了表 B 中的出版物 ID,用户可以选择要编辑的文档。
我需要做的是创建一个触发器,或者其他一些方法,当通过我们的输入表单提交请求时,检查它是否用于表 B 中文档的修订并标记“状态”列表 B 中的“正在进行修订”。
因此,它需要有条件地调用,或者在触发器本身中有某种 if 语句。同样,条件是如果在表 A 的输入表单上选择“修订”,则将所选出版物 ID 的状态设置为“修订进行中”。
谢谢!
Ok. So I know how to create a trigger that makes changes to Table B when an action is made on Table A. that is reletively easy and I am comfortable doing so. What I have been unable to do is to create a trigger that contains an if statement so that it executes if certain criteria are met.
Example:
Table A & Table B are related. Table A contains data concerning documents that are currently in processing which are identified by a unique processing code. Table B contains data about finalized and released documents which are identified by a Publication ID. Table A and Table B are related because a document may undergo many revisions and therefore it may appear multiple times in Table A (unique processing code but same Publication ID) while still only appearing in Table B once. The Publication ID remains the same throughout the course of the document's life no matter how many revisions it undergoes.
Table A is filled via an input form where people submit requests concerning documents they would like to have us process. They have the option of selecting to process a new document or if they would like to revise a current document that is already in Table B. This is done via a radio group (New, Revision etc...). If 'Revision' is selected then a select list box, that is populated with Publication IDs from Table B, appears and the user can select which document to edit.
What I need to do is create a trigger, or some other means, that will, when a request is submitted via our input form, check to see if it is for a revision of a document in Table B and mark the 'Status' column in Table B to 'Revision in Progress'.
So it would need to be either conditionally called or have some kind of if statement in the trigger itself. The condition, again, would be if 'Revision' is selected on Table A's input form then set the Status of the selected Publication ID to 'Revision in Progress'.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它应该是表 A 上的正常行级触发器,
伪代码应该是这样的..
在表 A 上为每一行创建或替换触发器 .....
如果:NEW.process_selected = '修订版' 那么
更新b
设置状态 = '正在进行修订'
其中publication_id = :publication_id ;
结束如果;
结尾 ;
-桑吉夫
It should be normal row level trigger on table A,
A pseudo code should be something like this..
create or replace trigger on table A for each row .....
if :NEW.process_selected = 'Revision' then
update b
set status = 'Revision in Progress'
where publication_id = :publication_id ;
end if;
end ;
-Sanjeev
我已经很久没有使用APEX了,但是表单提交不能是到pl/sql过程而不是直接到表吗?然后编写一个过程,根据输入参数采取适当的操作。
It's been a long time since I used APEX, but can't the form submission be to a pl/sql procedure rather than directly to a table? Then write a procedure that takes the appropriate action depending on the input parameters.