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

-- 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. python手记(42)

    #!/usr/bin/env python #-*- coding: utf-8 -*- #code:myhaspl@qq.com import cv2 import numpy as np fn1= ...

  2. wepy - 与原生有什么不同($pages,$interceptors)

    wepy内部封装的一些基类,我们要注意以 “$”开头命名,最好不用 关于wepy基类文档,请查看 关于$apply,其实就是主动刷新DOM,来更新数据. 何时使用它? 答. 你为data里面的数据进行 ...

  3. jQuery(一)引入

    一.jQuery简介 jQuery是一个兼容多浏览器的javascript库,核心理念是write less,do more(写得更少,做得更多) 二.安装 2.1.下载 下载地址:http://jq ...

  4. 解决运行Maven是报错:No goals have been specified for this build

    pom.xml文件<build>标签后面加上<defaultGoal>compile</defaultGoal>即可

  5. HDU 1023 Train Problem II 大数打表Catalan数

    一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...

  6. isearch5 index,attribute和summary。

    索引 isearch5 支持的索引分为:index,attribute和summary. Index指的是倒排索引,它存储了存储了从term到DocID的映射关系,形如: term-->(Doc ...

  7. python之模块csv之CSV文件一次写入多行

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #CSV文件一次写入多行 import csv #csv文件,是一种常用的文本格式,用以存储表格数据,很多程序 ...

  8. 9、java中static详解

    一.static关键字的用途 在<Java编程思想>P86页有这样一段话: “static方法就是没有this的方法.在static方法内部不能调用非静态方法,反过来是可以的.而且可以在没 ...

  9. nyoj-----D的小L

    D的小L 时间限制:4000 ms  |           内存限制:65535 KB 难度:2   描述       一天TC的匡匡找ACM的小L玩三国杀,但是这会小L忙着哩,不想和匡匡玩但又怕匡 ...

  10. Python websocket

    一.自己实现websocket 网上流传的都是Python2的websocket实现 # coding=utf8 # !/usr/bin/python import struct, socket im ...