将 oracle table 数据从两个 table 复制到另一个 table
Copy oracle table data from two tables to another table
这是我的 tables:
create table country(
country_id number(5) primary key,
country 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 插入到国家 table 如下:
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
对;发明自己的语法通常会导致您体验到的结果。您是要使用 distinct
吗?
SELECT DISTINCT a.city,
b.country_id
FROM airportdemodata a
JOIN country b ON a.country = b.country;
这是我的 tables:
create table country( country_id number(5) primary key, country 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 插入到国家 table 如下:
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
对;发明自己的语法通常会导致您体验到的结果。您是要使用 distinct
吗?
SELECT DISTINCT a.city,
b.country_id
FROM airportdemodata a
JOIN country b ON a.country = b.country;