更新前检查数据oracle sql

问题描述:

我想问一下编码的问题。更新前检查数据oracle sql

我想在更新之前先检查此条目的数据,否则什么都不要做。 例子:

first_name last_name salary dept_no 
John   Smith  5000  1 

If salary = 5000 and dept_no = 1 where last_name = 'Smith' 
and first_name = 'John', 
do nothing 
else update table and set salary = 5000 and dept_no = 1 
where last_name = 'Smith' 
and first_name = 'John' 

换句话说,如果数据已被设置为这个值,什么也不做,否则更新数据。

感谢任何反馈。

+0

:要求寻找突然,当你有表中的数据做任何其他事情更新.Rather是否存在数据更新做别的插入,你应该有一个像...如果我指正?我错了 – 2012-08-13 09:10:46

试试这个:

update <table> 
set salary = 5000 and dept_no = 1 
where last_name = 'Smith' 
and first_name = 'John' 
    and salary != 5000 
    and dept_no != 1 
+0

嗨,谢谢,但有没有办法做到这一点,如果否则然后声明plsql代码? – mysticfalls 2012-08-13 09:54:15

+0

@mysticfalls:这是做这件事最有效的方法..为什么你想在PLSQL中做到这一点? – 2012-08-13 10:32:26