Creating tables with fields from 2 different tables

人走茶凉 提交于 2019-12-04 18:43:23
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
    )

I'm no oracle guy, but that should do what you want (untested, though).

You were close:

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)

It depends on what you're going to use it for, but I'd be sorely tempted to use a view instead of a table:

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

The advantage is it always contains the values from the current versions of table_1 and table_2. The disadvantage is that you cannot edit the view (or, if you can, your edits affect the underlying tables as well as the view).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!