【问题标题】:Copy oracle table data from two tables to another table将oracle表数据从两个表复制到另一个表
【发布时间】:2021-09-26 01:04:15
【问题描述】:

这是我的桌子:

创建表国家( country_id number(5) 主键, 国家 varchar2(36) );

    create table city(
    city_id number(5) primary key,
    country_id number(5) constraint city_country_fk references country(country_id) NOT NULL,
    city varchar2(36)
    );

SQL> desc airportdemodata;
 Name                    Null?    Type
 ----------------------------------------- -------- ----------------------------
 AIRPORT_ID                  NOT NULL NUMBER(5)
 IATA_CODE                        VARCHAR2(3)
 CITY                         VARCHAR2(36)
 COUNTRY                      VARCHAR2(36)
 AIRPORT                      VARCHAR2(58)

我将来自 airportdemodata 的国家/地区插入到国家/地区表中,如下所示:

INSERT INTO country (country)
SELECT unique(country) from airportdemodata;

效果很好。
现在我正在尝试通过将 airportdemodata.country 与 country.country 匹配来将 airportdemodata.city 复制到 city.city(country_id,city) 中。我试过这样:

SQL> SELECT a.unique(city), b.country_id FROM airportdemodata a, country b where a.country=b.country;
SELECT a.unique(city), b.country_id FROM airportdemodata a, country b where a.country=b.country
         *
ERROR at line 1:
ORA-01747: invalid user.table.column, table.column, or column specification

【问题讨论】:

    标签: sql oracle oracle11g oracle-xe


    【解决方案1】:

    对;发明自己的语法通常会导致您体验到的结果。您的意思是使用distinct

    SELECT DISTINCT a.city,
                    b.country_id
    FROM airportdemodata a
    JOIN country b ON a.country = b.country;
    

    【讨论】:

    • 独特和独特的区别是什么?
    • 其实没有。我一直在使用 DISTINCT 可能 100% 次和 UNIQUE 0%。这是你使用它的方式;不是SELECT a.unique(city) ...,而是SELECT unique a.city ...
    猜你喜欢
    • 1970-01-01
    • 2012-07-13
    • 1970-01-01
    • 1970-01-01
    • 2012-11-24
    • 2011-05-16
    • 2023-03-16
    • 1970-01-01
    • 2011-11-21
    相关资源
    最近更新 更多