无论我对触发器执行什么操作,总是返回“插入0行”。 就像在插入新值之后找不到新值。 添加异常后,它返回no_data_found,我不知道为什么。
# define a function that makes all key names follow the same guidelines (normalization)
def normalize_keyname(key):
return key.lower()
before = [
{'Accepted Currencies (DASH)': 'DASH'},
{'Accepted Currencies (Dash)': 'Dash'}
]
after = [
{normalize_keyname(key): value for key, value in entry.items()}
for entry in before
]
for entry in after:
print(entry)
答案 0 :(得分:1)
看来您做错了方法。原因如下:
autonomous_transaction
,它将触发代码与主事务隔离开来您不应出于此目的使用该编译指示。幸运的是,触发器可以用一种更简单的方式重写,即不会引起变异表错误的触发器。当您要比较rent_date
和return_date
时,请直接进行比较。这是一个示例(请参阅第5行):
SQL> create table rent
2 (id number,
3 rent_date date,
4 return_date date
5 );
Table created.
SQL> create or replace trigger trg_biu_rent
2 before insert or update on rent
3 for each row
4 begin
5 if :new.return_date < :new.rent_date then
6 raise_application_error (-20158, 'Return date must be after the rent date');
7 end if;
8 end;
9 /
Trigger created.
测试:
SQL> -- This will fail
SQL> insert into rent (id, rent_date, return_date) values
2 (1, date '2019-05-25', date '2019-04-10');
insert into rent (id, rent_date, return_date) values
*
ERROR at line 1:
ORA-20158: Return date must be after the rent date
ORA-06512: at "SCOTT.TRG_BIU_RENT", line 3
ORA-04088: error during execution of trigger 'SCOTT.TRG_BIU_RENT'
SQL> -- This is OK
SQL> insert into rent (id, rent_date, return_date) values
2 (1, date '2019-03-28', date '2019-10-20');
1 row created.
SQL>