在SQL中,如何在更新数据库表中的“非空"值时引发错误 [英] In SQL how do I throw an error when updating 'not null' values in a database table

查看:93
本文介绍了在SQL中,如何在更新数据库表中的“非空"值时引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我要更新的值是非空"值的情况下引发错误.

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

例如.在下表中,说我想用'Jackson'更新Paul的姓氏. SQL应该抛出一个错误,说明正在更新的值是'not null'.

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'.

姓氏
保罗·帕金森
彼得null
土耳其null

First Lastname
Paul Parkinson
Peter null
Turkey null

作为此问题的第二部分,我实际上正在APEX Express数据加载向导中进行此操作.如果有人知道如何修改更新命令来做到这一点,将不胜感激

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

推荐答案

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

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

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

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

这篇关于在SQL中,如何在更新数据库表中的“非空"值时引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆