【问题标题】:Data Sync between 2 tables in Oracle DatabaseOracle 数据库中 2 个表之间的数据同步
【发布时间】:2015-05-30 03:36:38
【问题描述】:

我有 2 个表,即 table1(id、name、address、contact_number、gender)和 table2(id、name、contact_number)使用 Oracle 11g XE。

在表 1 中,我有数据:(1,约翰,雅加达,123345,男性),(2,雷纳,万隆,568955,女性)。我想要基于 table1 到 table2 的数据,例如 (1, john, 123345), (2, reina, 568955)。

table1 有新数据后,如 (3, alfiano, Meda, 789654, male),table2 不存在重复数据(john 和 reina),只是添加 alfiano 数据值。

当我查询触发器时

select trigger_name, trigger_type, triggering_event, trigger_body from all_triggers where table_name = 'TABLE1'

在这种情况下,我有一个按钮来执行同步。但我不知道代码了。我正在使用 C#。

private void btnSync_Click(object sender, EventArgs e)
    {
        // i don't know the code
    }

如何在这些表之间同步数据? 谁能推荐我?

【问题讨论】:

  • aminvincent,我们需要更多信息。您在 table1 上是否有更新 table2 的触发器?如果是这样,请将触发代码添加到您的问题中。
  • @EdGibbs 在这种情况下,我有一个执行按钮,但我不知道代码....我正在使用 C#...你能建议我吗?
  • 要检查您的 table1 上是否有任何触发器,请使用以下查询:select trigger_name, trigger_type, triggering_event, trigger_body from all_triggers where table_name = 'TABLE1'
  • 很抱歉@aminvincent,但没有足够的信息来回答您的问题。如果您有更多信息,请发布。
  • @DmitryEgorov 我检查了table1中的触发器,但没有找到任何东西,..这意味着我没有触发器??

标签: c# oracle11g sync


【解决方案1】:

尝试以下触发器定义,以便将table1的数据自动反映到table2中:

create or replace trigger table1_fill_table2
after insert on table1
for each row
begin
    insert into table2
        select :new.id, :new.name, :new.contact_number
        from dual;
end;
/

但是请注意,您应该避免使用仅对table2 进行部分修改的代码。这大概是btnSync_Click

有关触发器的更多信息,请参阅 Oracle 文档:

http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/triggers.htm#LNPLS020 -- 通用用法说明

http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/create_trigger.htm#LNPLS01374 -- 用于触发器定义语法

【讨论】:

    猜你喜欢
    • 2011-04-09
    • 2017-12-12
    • 1970-01-01
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    • 2014-03-31
    • 2022-12-28
    • 1970-01-01
    相关资源
    最近更新 更多