首先创建两个结构相同的表

-- Create table
create table TABLE_TEMP
(
userid NUMBER not null,
username NVARCHAR2(50),
userno NVARCHAR2(60),
cardid NVARCHAR2(18),
createdate DATE,
redate DATE,
month VARCHAR2(6),
amount NUMBER
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 16
next 8
minextents 1
maxextents unlimited
);

第二个表结构

-- Create table
create table TEST_TABLE_TEMP
(
userid NUMBER not null,
username NVARCHAR2(50),
userno NVARCHAR2(60),
cardid NVARCHAR2(18),
createdate DATE,
redate DATE,
month VARCHAR2(6),
amount NUMBER
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 16
next 8
minextents 1
maxextents unlimited
);

其中这两个表的ID都是不能自动增长的属性 没有建立sequences 序列以及自动增长的触发器

建立触发器:

create or replace trigger triggers_table_tempToTemp
before insert or update or delete
on table_temp for each row
declare
integrity_error exception;
errno integer;
errmsg char(200);
dummy integer;
found boolean; begin if inserting then
insert into test_table_temp(userid,UserName,userno,cardid,createdate,redate,month,amount)
values(:NEW.userid,:NEW.UserName,:NEW.userno,:new.cardid,:NEW.createdate,:NEW.redate,:NEW.month,:NEW.amount);
elsif updating then
update test_table_temp set userid=:NEW.userid,
UserName=:NEW.UserName,userno=:NEW.userno,
cardid=:NEW.cardid ,createdate=:NEW.createdate,
redate=:NEW.redate,
month=:NEW.month,
amount=:NEW.amount
where USERID=:OLD.USERID;
elsif deleting then
delete from test_table_temp where userid=:OLD.userid;
end if;
exception
when integrity_error then
raise_application_error(errno, errmsg);
end;
--执行报错,错误信息:ORA-04084 无法更改此触发器类型的NEW值
--把触发器的after改成before 触发
--实现数据增删改 同时实现两个数据表同步信息

测试数据

insert into TABLE_temp(userid,USERNAME,USERNO,CARDID,CREATEDATE,REDATE,MONTH,AMOUNT)
values('1','小晴','20140408','201404087976',to_date('2014-04-08','yyyy-mm-dd'),to_date('2014-04-08','yyyy-mm-dd'),'201404','100000') update TABLE_temp set USERNAME='小清新' where userid=1
delete from TABLE_temp where userid=1

数据库中把一个表中的数据复制到另一个表中 如果不用其他方法直接用SQL语句实现:

1、如果是整个表复制如下:
insert into table1 select  * from table2
2、如果是有选择性的复制数据如下:
insert into table1(column1,column2,column3...) select column1,column2,colunm3... from table2
3、一个数据库中的表中的数据复制到另一个数据库中的一个表,使用方法如下:
insert into 数据库A.dbo.table1(col1,col2,col3...) select col1,col2,col3... from 数据库B.dbo.table2

oracle triggers 实现两个结构相同的表的数据级联更新操作的更多相关文章

  1. oracle 批量更新之将一个表的数据批量更新至另一个表

      oracle 批量更新之将一个表的数据批量更新至另一个表 CreationTime--2018年7月3日17点38分 Author:Marydon Oracle 将一个表的指定字段的值更新至另一个 ...

  2. SQLSEVER 不同服务器下两个结构相似的表实现数据同步(触发器)

    1.建立链接服务器 在ServerA 中创建指向ServerB的链接服务器,并做好账号映射.addlinkedserver存储过程创建一个链接服务器,参数详情参见官方文档. 第1个参数LNK_Serv ...

  3. SQL 两张结构一样的表合并查询 .

    select * from table1 union all select * from table2 union all 是所有的都显示出来: select * from table1 union ...

  4. SQL 将两个结构相同的表合并到成一个表

    select * into 新表名 from (select * from T1 union all select * from T2) 这个语句可以实现将合并的数据追加到一个新表中. 不合并重复数据 ...

  5. Oracle数据库中将一个数据库中一张表的数据导入到另外一张表

    INSERT INTO DBTHNEW.L_MEMBER_ROLE_REL SELECT    *FROM    DBTH.L_MEMBER_ROLE_REL

  6. JDBC获得DB2表结构并且将表中数据脱敏后转移的程序示例

    完整项目地址:https://github.com/zifeiy/totomi 代码示例: import java.io.File; import java.io.FileInputStream; i ...

  7. mybatis+Oracle 批量插入数据,有数据做更新操作

    <!-- 批量添加 -->     <insert id="batchAdd" parameterType="java.util.List"& ...

  8. Oracle 给表添加主键和使ID自增、触发器、创建结构一样的表

    1.关于主键:在建表时指定primary key字句即可:create table test( id number(6) primary key, name varchar2(30));如果是对于已经 ...

  9. oracle、mysql、sybase和sqlserver复制表结构和数据

    Sql Server(sybase): 1.复制表结构: 新建表student2,并且结构同表syn_xj_student一致.Sql语句如下: 2.复制表数据,并排除俩表中相同的数据: insert ...

随机推荐

  1. php之快速入门学习-5(常量)

    PHP 5 常量 常量值被定义后,在脚本的其他任何地方都不能被改变. PHP 常量 常量是一个简单值的标识符.该值在脚本中不能改变. 一个常量由英文字母.下划线.和数字组成,但数字不能作为首字母出现. ...

  2. hadoop safemode error

    http://www.cnblogs.com/hustcat/archive/2010/06/30/1768506.html 1.safemode bin/hadoop fs -put ./input ...

  3. Using QuickExec

    Fiddler's QuickExec box allows you to launch script-commands quickly. Keyboard Shortcuts Hit ALT+Q t ...

  4. Android Bitmap与String互转(转)

    /** * 图片转成string * * @param bitmap * @return */ public static String convertIconToString(Bitmap bitm ...

  5. C#:确保绑定到同一数据源的多个控件保持同步

    下面的代码示例演示如何使用 BindingSource 组件,将三个控件(两个文本框控件和一个 DataGridView 控件)绑定到 DataSet 中的同一列.该示例演示如何处理BindingCo ...

  6. Linux生成高强度密码

    在撰写,自动化脚本.往往需要添加账户及密码.如何自动化填写随机密码,有点意思.... 01.openssl生成密码 [root@mvp ~]# openssl rand -base 14Usage: ...

  7. OpenWrt的开机启动服务(init scripts)

    参考 https://wiki.openwrt.org/doc/techref/initscripts 以一个简单的例子来说明 #!/bin/sh /etc/rc.common # Example s ...

  8. 【微信小程序】解决 竖向<scroll-view>组件 “竖向滚动页面出现遮挡”问题

    问题图: 问题原因: <scroll-view class="scroll-container" upper-threshold="{{sortPanelDist} ...

  9. ios block常见的错误(二)——循环引用

    这篇博文继续block的常见错误——循环引用. 循环引用是很多初学者不能察觉的,其产生的原因,是block中的代码会对对象进行强引用. 读者请阅读示例代码1,并思考示例代码1所创建的对象能否被正常销毁 ...

  10. 搭建前端vue环境,安装vue-cli遇到Please try running this command again as root/Administrator的解决方案

    最近在搭前端环境,装完node.js之后,准备安装vue工程的初始化工具时(npm install -g vue-cli),遇到这个坑: 大体的意思就是权限问题,导致/usr/local/lib/no ...