plsql 在 'before alter' 触发器中获取 table

plsql get table in 'before alter' trigger

我有一个 table 身份,我还有一个 table ident_hist,它只保留来自 table 身份的日志。 table 标识发生了很大变化,因此我也想将新列动态添加到 ident_hist。我创建了一个程序来执行此操作:

create or replace procedure prc_create_hist_tabel(p_naam_hist_tabel in varchar2, p_naam_tabel in varchar2) is
cursor c is 
    select 'alter table ' || p_naam_hist_tabel || ' add ' || column_name || ' ' || data_type || case when data_type = 'DATE' then null else '(' || data_length || ')' end lijn 
    from user_tab_columns 
    where TABLE_NAME = upper(p_naam_tabel) 
    and column_name not in (select column_name from user_tab_columns where table_name = upper(p_naam_hist_tabel));

    v_dummy number(1);
begin
    begin
        select 1 into v_dummy
        from user_tab_columns
        where TABLE_NAME = upper(p_naam_hist_tabel)
        group by 1;
    exception when no_data_found then
        execute immediate 'create table ' || p_naam_hist_tabel || ' (wijziger varchar2(60) default user, wijzigdatum date default sysdate, constraint pk_' || p_naam_hist_tabel || ' primary key (wijziger, wijzigdatum))';
    end;

    for i in c
    loop
        execute immediate i.lijn;
    end loop;
end;

我的问题是,如果我正在更改表格标识,我该如何签入我的 DDL 触发器?

我想做这样的事情:

create or replace trigger ident_hist_trig before alter on ident
begin
    prc_create_hist_tabel('ident_hist', 'ident');
end;

当我尝试编译触发器时,收到此错误消息:

ORA-30506: system triggers cannot be based on tables or views

如果我正在更改我的 table 身份,我该如何检查我的 DDL 触发器?我只想在更改 table 标识时触发它,而不是任何其他 table.

30506, 00000, "system triggers cannot be based on tables or views"

Cause: An attempt was made to base a system trigger on a table or a view.
Action: Make sure the type of the trigger is compatible with the base object.

系统触发器不与单个对象相关联。 您可以在创建或更改或删除 SCHEMA (User/Owner) 之前创建 DDL 触发器。然后您可以过滤对象名称和 DDL 类型(DROP、ALTER)。

Tom在这里详细解释了这一点。 Writting DDL_EVENT Triggers