我有一个基于表格的可编辑交互式网格。我想使用进行更改的日期更新MODIFIED_DTS,并使用MODIFIED_BY_USR_ID更新用户在表中进行任何更改时自动进行更改的人员。
有什么方法可以实现?
是的,绝对有一种方法可以实现这一点。到目前为止,最好的方法是在交互式网格所基于的表上创建触发器。生成此触发器的最简单方法是使用livesql.oracle.com上的quicksql。它会生成这样的触发器:
create or replace trigger <your_table_name>_BIU
before insert or update
on <your_table_name>
for each row
begin
if inserting then
:new.created := sysdate;
:new.created_by := nvl(sys_context('APEX$SESSION','APP_USER'),user);
end if;
:new.updated := sysdate;
:new.updated_by := nvl(sys_context('APEX$SESSION','APP_USER'),user);
end tp_item_biu;
/
用您的列名替换your_table_name和“ created,created_by,updated,updated_by”,进行编译,您就很好了。
是的,您将为此使用数据库表触发器。好处是,它可以在您修改了表的应用程序中的任何地方使用,此外,如果您的应用程序外部的人修改了表,它也可以使用。合并将首先查看是否在APEX上下文中执行了插入/更新,并使用app_user(如果未使用当前数据库用户)。
create or replace trigger my_trigger_name
before insert or update on my_table
for each row
begin
:new.modified_dts := sysdate;
:new.modified_by_user_id := coalesce(sys_context('APEX$SESSION', 'APP_USER'), user);
end;
/