简体   繁体   English

Oracle 在 StmTbl 上插入或删除或更新之前的 PL SQL/触发器

[英]Oracle PL SQL/Trigger before insert or delete or update on StmTbl

How can i avoid null value of:old or new?我怎样才能避免 null 的价值:旧的或新的? Im trying to insert to one table 3 step before update,delete,insert with having more columns我试图在更新、删除、插入具有更多列之前的第 3 步插入一个表

How can i avoid null value of:old or new?我怎样才能避免 null 的价值:旧的或新的?

Both old and new pseudorecords reflect values in the table (old ones are "previous", new ones are... well, "new", which will replace old ones). oldnew的伪记录都反映了表中的值(旧的是“以前的”,新的是......好吧,“新的”,它将取代旧的)。

Suppose there's a job column in the table and its value is NULL .假设表中有一个job列,它的值为NULL If you run如果你跑

update emp set job = 'CLERK' where empno = 7369;

then :old.job = NULL , :new.job = 'CLERK' .然后:old.job = NULL , :new.job = 'CLERK'

Or, the opposite : suppose there was 'ANALYST' in that column and you run或者,相反:假设该列中有“ANALYST”并且您运行

update emp set job = null where empno = 7369;

so :old.job = 'ANALYST' , :new.job = NULL .所以:old.job = 'ANALYST' , :new.job = NULL


You asked how to avoid null ;你问如何避免null why would you want to "avoid" them?你为什么要“避开”他们? They have values they should have.他们有他们应该有的价值观。 There's nothing wrong in NULL as it means that there's an absence of a value. NULL没有任何问题,因为它意味着没有值。

In the 1st example above (where :old.job = null ), what would you want to use instead of it?在上面的第一个示例中(其中:old.job = null ),您想使用什么来代替它? There was no value there...那里没有任何价值......

If you must (although, I don't know why), you could use NVL or COALESCE functions or CASE expression;如果必须(尽管我不知道为什么),您可以使用NVLCOALESCE函数或CASE表达式; for example:例如:

insert into log_table (job) values (nvl(:old.job, 'no previous job'));

insert into log_table (job) values (coalesce(:old.job, 'no previous job'));

insert into log_table (job), values (case when :old.job is null then 'no previous job'
                                          else :old.job
                                     end);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM