在 SQL 中,如何在更新数据库 table 中的 'not null' 值时抛出错误

In SQL how do I throw an error when updating 'not null' values in a database table

希望在我更新的值是 'not null' 值时引发错误。

例如。在下面的 table 中,假设我想将 Paul 的姓氏更新为 'Jackson'。 SQL 应该抛出一个错误,表明正在更新的值是 'not null'.

First Lastname
Paul Parkinson
Peter null
Turkey null

作为这个问题的第二部分,我实际上希望在 APEX Express 数据加载向导中执行此操作。如果有人知道如何修改更新命令来执行此操作,将不胜感激

您需要使用触发器来执行此操作。触发器示例:

create trigger schema.trigger_name
    before update of last_name
    on tablename
    for each row
begin
    if :old.last_name is not null then
        raise_application_error (-20100, 'Last name already has a value');
    end if;
end;
/

但这会通过引发 plsql 错误来停止任何 运行 的进程。