table1 有3个字段(序号,字母 varchar2,数字 varchar2)序号 字母 数字
001 A 2
002 E 5如果更新的值是 '不变',那么值不变例 update table1 set 字母='不变',数字='100' where 序号=001
update table1 set 字母='不变',数字='不变' where 序号=002更新后:序号 字母 数字
001 A 100
002 E 5请问这个触发器该怎么写
001 A 2
002 E 5如果更新的值是 '不变',那么值不变例 update table1 set 字母='不变',数字='100' where 序号=001
update table1 set 字母='不变',数字='不变' where 序号=002更新后:序号 字母 数字
001 A 100
002 E 5请问这个触发器该怎么写
解决方案 »
- imp导入表出现问题,必须表不存在的情况下才成功。如果表存在就报错了
- oracle用存储过程 网clob字段插入值的问题
- SQL查询问题,求帮忙解决一下
- ★★★★★★★ 天啊, 这就是 CSDN ? 太让我失望了! ★★★★★★★
- 关于游标 时间循环
- 问个简单的问题,求助!!!!!!!!!!!!!!!!!!!!!!!!
- ★☆★☆★ 300分 求使用过long或者clob字段的大虾解释一个问题
- 在存储过程中用传递参数形成sql语句
- 安装oracle9i 企业办的时候必须指定的 TNS Connect String 是干什么的?应该怎么设
- 寻求技术指导
- Oracle触发器问题
- 存储过程返回影响行数 不对啊
before update on table1
for each row
when(new.字母='不变' or new.数字='不变')
begin
if :new.字母='不变' then
:new.字母:=:old.字母;
end if;
if :new.数字='不变' then
:new.数字:=:old.数字;
end if;
end;不过一般不要这样用,既然不需要更新为什么要更新成'不变'...
update table1 set 数字='100' where 序号=001 不就好了
SQL> drop table table1;表已丢弃。SQL> create table table1(序号 varchar2(100),字母 varchar2(100),数字 varchar2(100));表已创建。SQL> insert into table1 values('001','A','2');已创建 1 行。SQL> insert into table1 values('002','E','5');已创建 1 行。SQL> select * from table1;序号 字母 数字
---------- ---------- ----------
001 A 2
002 E 5SQL> create or replace trigger t_update_test
2 before update on table1
3 for each row
4 when(new.字母='不变' or new.数字='不变')
5 begin
6 if :new.字母 = '不变' then
7 :new.字母 := :old.字母;
8 end if;
9 if :new.数字 = '不变' then
10 :new.数字 := :old.数字;
11 end if;
12 end;
13 /触发器已创建SQL>
SQL> update table1 set 字母='不变',数字='100' where 序号='001';已更新 1 行。SQL> update table1 set 字母='不变',数字='不变' where 序号='002';已更新 1 行。SQL> select * from table1;序号 字母 数字
---------- ---------- ----------
001 A 100
002 E 5SQL>
--更新后抛异常信息的写法。
create or replace trigger trigger_table1
before update on table1
for each row
when(new.字母='不变' or new.数字='不变')
begin
raise_application_error('-20001','字段[字母]或者[数字]不允许更新成[不变]');
end;
/--更新后把原值更新回去的写法。
create or replace trigger trigger_table1
before update on table1
for each row
when(new.字母='不变' or new.数字='不变')
begin
:new.字母=:old.字母;
:new.数字=:old.数字;
end;
/