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

a 夏天 提交于 2019-12-13 05:59:08

问题


Looking to throw an error where the value i'm updating is a 'not null' value.

For example. In below table, say I wanted to update Paul's lastname with 'Jackson'. The SQL should throw an error to say that the value that is being updated is 'not null'.

First Lastname
Paul Parkinson
Peter null
Turkey null

As a second part to this question, I'm actually looking to do this in the APEX Express Data Load Wizard. If anyone would know how to modify the update command to do this, it would be greatly appreciated


回答1:


You need to do this with a trigger. Example trigger:

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;
/

But this will stop any process that is running by raising a plsql error.



来源:https://stackoverflow.com/questions/32904466/in-sql-how-do-i-throw-an-error-when-updating-not-null-values-in-a-database-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!