Oracle 触发器 插入|更新|删除,两表同步
来源:互联网 发布:淘宝买手机花呗分期购 编辑:程序博客网 时间:2024/05/17 08:17
表空间1:usi;
create table User_Info (
ID INTEGER not null,
UserName VARCHAR(30) not null,
PassWord VARCHAR(20) not null,
CreateDate Date not null,
Status INTEGER not null,
constraint PK_User_Info primary key (ID)
);
表空间2:ust;
create table User_Info_temp (
ID INTEGER not null,
UserName VARCHAR(30) not null,
PassWord VARCHAR(20) not null,
CreateDate Date not null,
Status INTEGER not null,
constraint PK_User_Info_temp primary key (ID)
);
触发器写法:
create or replace trigger UserToTemp after insert or update or delete
on user_info for each row
declare
integrity_error exception;
errno integer;
errmsg char(200);
dummy integer;
found boolean;
begin
if inserting then
insert into ust.User_info_temp(ID,UserName,PassWord,CreateDate,Status) values(:NEW.ID,:NEW.UserName,:NEW.PassWord,:new.CreateDate,:NEW.Status);
elsif updating then
update ust.User_info_temp set ID=:NEW.ID,UserName=:NEW.UserName,PassWord=:NEW.PassWord,Status=:NEW.Status where id=:OLD.id;
elsif deleting then
delete from ust.User_info_temp where id=:OLD.id;
end if;
exception
when integrity_error then
raise_application_error(errno, errmsg);
end;
create table User_Info (
ID INTEGER not null,
UserName VARCHAR(30) not null,
PassWord VARCHAR(20) not null,
CreateDate Date not null,
Status INTEGER not null,
constraint PK_User_Info primary key (ID)
);
表空间2:ust;
create table User_Info_temp (
ID INTEGER not null,
UserName VARCHAR(30) not null,
PassWord VARCHAR(20) not null,
CreateDate Date not null,
Status INTEGER not null,
constraint PK_User_Info_temp primary key (ID)
);
触发器写法:
create or replace trigger UserToTemp after insert or update or delete
on user_info for each row
declare
integrity_error exception;
errno integer;
errmsg char(200);
dummy integer;
found boolean;
begin
if inserting then
insert into ust.User_info_temp(ID,UserName,PassWord,CreateDate,Status) values(:NEW.ID,:NEW.UserName,:NEW.PassWord,:new.CreateDate,:NEW.Status);
elsif updating then
update ust.User_info_temp set ID=:NEW.ID,UserName=:NEW.UserName,PassWord=:NEW.PassWord,Status=:NEW.Status where id=:OLD.id;
elsif deleting then
delete from ust.User_info_temp where id=:OLD.id;
end if;
exception
when integrity_error then
raise_application_error(errno, errmsg);
end;
阅读全文
0 0
- Oracle 触发器 插入,更新,删除,数据同步,两表同步
- Oracle 触发器 插入,更新,删除,数据同步,两表同步
- Oracle 触发器 插入,更新,删除,数据同步,两表同步
- Oracle 触发器 插入,更新,删除,数据同步,两表同步
- Oracle 触发器 插入,更新,删除,数据同步,两表同步
- Oracle 触发器 插入,更新,删除,数据同步,两表同步
- Oracle 触发器 插入|更新|删除,两表同步
- 触发器 两表同步更新
- Oracle 触发器两表同步
- Microsoft SQL Server 触发器更新、删除、插入表
- 相同表结构 一个表结构插入更新删除更新同步另外一个表 触发器设计 inserted,deleted 均为系统临时表
- Oracle触发器实现插入或更新一张表数据同时插入或更新另一张表
- oracle触发器(当插入或删除或修改一张表A时,能把新数据同步到另一张结构相同的表B里面)
- Mysql创建触发器实现不同表的插入、更新、删除操作
- Mysql创建触发器实现不同表的插入、更新、删除操作
- 触发器中判断 插入 or 更新 or 删除
- 使用触发器操作表1(添加,更新,删除) 同步实现表2的操作
- Sql Server 触发器实现多表之间同步增加、删除与更新
- SQL语句中如何使用含有if....else...判断语句
- cv::mat的基本操作 ***** **
- FFMPEG计算PSNR存在的问题及解决方法
- JZ2440的中断控制器
- 机器学习-->数学基础
- Oracle 触发器 插入|更新|删除,两表同步
- Spring Shiro登陆验证技术详解
- Hadoop之Hive框架学习(笔记18)
- SQL Server 日期和时间函数
- 机器学习基石 3.2 Learning with Different Data Label
- linux和windows安装openOffice将excel、doc文件转成pdf或html
- 深入聊聊微服务架构的身份认证问题
- 深入浅出spi驱动之数据结构(一)
- 【Android】Android清除本地数据缓存代码