【问题标题】:Creating tables with fields from 2 different tables使用来自 2 个不同表的字段创建表
【发布时间】:2009-07-22 04:34:19
【问题描述】:

我想创建一个表来存储来自两个不同表的值;

从表 1:cust_id (varchar2)、invoice_amt (float)

来自表 2:cust_id(来自表 1)、payment_date

我的表格应该有 3 个字段:

cust_id, invoice_amt, payment_date

我尝试了以下,这显然是错误的。

create table temp1 as (
    select table_1.cust_id, table_1.invoice_amt, table_2.payment_date
      from table_1@dblink, table_2@dblink)

您的宝贵建议将有很大帮助。

【问题讨论】:

  • 专家您好,感谢您的意见。我已经开始创建表,但我的问题是,我的表有超过 700 万条记录,加上它试图通过 dblink 访问记录。无论如何我可以加快查询速度吗?我是一个完全的新手,所以一些详细的帮助会很棒。非常感谢:)

标签: sql oracle oracle10g


【解决方案1】:
create table temp1 as (
    select 
        table_1.cust_id,
        table_1.invoice_amt,
        table_2.payment_date 
    from 
        table_1@dblink, 
        table_2@dblink 
    where 
        table_1.cust_id = table_2.cust_id
    )

我不是预言家,但这应该可以满足您的需求(尽管未经测试)。

【讨论】:

    【解决方案2】:

    你很亲密:

    create table temp1 as ( 
        select t1.cust_id, t1.invoice_amt, t2.payment_date 
          from table_1@dblink t1, table_2@dblink t2 
         where t1.cust_id=t2.cust_id)
    

    【讨论】:

      【解决方案3】:

      这取决于您将其用于什么,但我非常想使用视图而不是表格:

      create view temp1(cust_id, invoice_amt, payment_date) as
          select t1.cust_id, t1.invoice_amt, t2.payment_date 
            from table_1@dblink as t1 inner join table_2@dblink as t2
                 on t1.cust_id = t2.cust_id
      

      优点是它始终包含当前版本的 table_1 和 table_2 中的值。缺点是您无法编辑视图(或者,如果可以,您的编辑会影响基础表以及视图)。

      【讨论】:

      • 缺点还在于,您必须通过 DB 链接为对该视图的每个查询提取数据。
      猜你喜欢
      • 2016-02-22
      • 2021-11-02
      • 2015-11-07
      • 2019-01-25
      • 2015-09-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-09
      • 1970-01-01
      相关资源
      最近更新 更多