Bo's Oracle Station

【博客文章2026】MySQL 9.x数据库管理技巧9:将数据从MySQL数据库导出并导入Oracle数据库

2026-3-28 01:42| 发布者: admin| 查看: 51| 评论: 0|原作者: Bo Tang

摘要: 为了和Oracle数据库作对比,通常需要从MySQL 9.x数据库中导出相同的用户方案,并导入用作对比的Oracle数据库中。本博客通过详细的原创实验记录展示该过程的技术细节,并给出一个完全成功的MySQL数据库导出数据和Oracle数据库导入数据的案例。导入时,根据导出文件的特性,选择性地采用了SQLLOADER和外部表技术。
【博客文章2026】MySQL 9.x数据库管理技巧9:将数据从MySQL数据库导出并导入Oracle数据库



Author: Bo Tang

1. 为了和Oracle数据库作对比,需要从MySQL 9.x数据库中导出相同的用户方案

1.1 从MySQL 9.6数据库导出world_y数据库之前,作如下检查:

[root@station95 mysql]# mysqlcheck -u root -p  world_y
Enter password: 
world_y.city                                       OK
world_y.country                                    OK
world_y.countryinfo                                OK
world_y.countrylanguage                            OK
world_y.countrylanguage2                           OK

    查看MySQL数据库里的表信息:

[root@station95 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 9.6.0 MySQL Community Server - GPL

Copyright (c) 2000, 2026, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use world_y;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-------------------+
| Tables_in_world_y |
+-------------------+
| city              |
| country           |
| countryinfo       |
| countrylanguage   |
| countrylanguage2  |
+-------------------+
5 rows in set (0.003 sec)

1.2 从MySQL 9.6数据库中导出world_y数据库中的我们所需要的表:
    查看默认导出目录:

mysql> SHOW VARIABLES LIKE 'secure_file_priv';
+------------------+-----------------------+
| Variable_name    | Value                 |
+------------------+-----------------------+
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
1 row in set (0.008 sec)

    导出city表、country表、countryinfo表和countrylanguage表:

mysql> use world_y;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * into outfile '/var/lib/mysql-files/city.txt' from city;
Query OK, 4074 rows affected (0.014 sec)

mysql> select * into outfile '/var/lib/mysql-files/country.txt' from country;
Query OK, 239 rows affected (0.002 sec)

mysql> select * into outfile '/var/lib/mysql-files/countryinfo.txt' from countryinfo;
Query OK, 239 rows affected (0.007 sec)

mysql> select * into outfile '/var/lib/mysql-files/countrylanguage.txt' from countrylanguage;
Query OK, 984 rows affected (0.003 sec)

    查看生成的文件:

[root@station95 ~]# cd /var/lib/mysql-files/
[root@station95 mysql-files]# ls -l
total 332
-rw-r----- 1 mysql mysql 209506 Mar 29 02:05 city.txt
-rw-r----- 1 mysql mysql  97654 Mar 30 23:01 countryinfo.txt
-rw-r----- 1 mysql mysql  18251 Mar 30 23:03 countrylanguage.txt
-rw-r----- 1 mysql mysql   5424 Mar 30 23:00 country.txt

    查看每个生成的文件的内容:
    city.txt:   

[oracle@classroom ~]$ head -n 10 city.txt 
1       Kabul   AFG     Kabol   {"Population": 1780000}
2       Qandahar        AFG     Qandahar        {"Population": 237500}
3       Herat   AFG     Herat   {"Population": 186800}
4       Mazar-e-Sharif  AFG     Balkh   {"Population": 127800}
5       Amsterdam       NLD     Noord-Holland   {"Population": 731200}
6       Rotterdam       NLD     Zuid-Holland    {"Population": 593321}
7       Haag    NLD     Zuid-Holland    {"Population": 440900}
8       Utrecht NLD     Utrecht {"Population": 234323}
9       Eindhoven       NLD     Noord-Brabant   {"Population": 201843}
10      Tilburg NLD     Noord-Brabant   {"Population": 193238}
......

    country.txt:

[oracle@classroom ~]$ head -n 10 country.txt 
ABW     Aruba   129     AW
AFG     Afghanistan     1       AF
AGO     Angola  56      AO
AIA     Anguilla        62      AI
ALB     Albania 34      AL
AND     Andorra 55      AD
ANT     Netherlands Antilles    33      AN
ARE     United Arab Emirates    65      AE
ARG     Argentina       69      AR
ARM     Armenia 126     AM
......

    countryinfo.txt:

[oracle@classroom ~]$ head -n 10 countryinfo.txt
{"GNP": 828, "_id": "00005de917d80000000000000000", "Code": "ABW", "Name": "Aruba", "IndepYear": null, "geography": {"Region": "Caribbean", "Continent": "North America", "SurfaceArea": 193}, "government": {"HeadOfState": "Beatrix", "GovernmentForm": "Nonmetropolitan Territory of The Netherlands"}, "demographics": {"Population": 103000, "LifeExpectancy": 78.4000015258789}}    00005de917d80000000000000000    {"type": "object"}
{"GNP": 5976, "_id": "00005de917d80000000000000001", "Code": "AFG", "Name": "Afghanistan", "IndepYear": 1919, "geography": {"Region": "Southern and Central Asia", "Continent": "Asia", "SurfaceArea": 652090}, "government": {"HeadOfState": "Mohammad Omar", "GovernmentForm": "Islamic Emirate"}, "demographics": {"Population": 22720000, "LifeExpectancy": 45.900001525878906}}      00005de917d80000000000000001    {"type": "object"}
{"GNP": 6648, "_id": "00005de917d80000000000000002", "Code": "AGO", "Name": "Angola", "IndepYear": 1975, "geography": {"Region": "Central Africa", "Continent": "Africa", "SurfaceArea": 1246700}, "government": {"HeadOfState": "José Eduardo dos Santos", "GovernmentForm": "Republic"}, "demographics": {"Population": 12878000, "LifeExpectancy": 38.29999923706055}} 00005de917d80000000000000002    {"type": "object"}
{"GNP": 63.20000076293945, "_id": "00005de917d80000000000000003", "Code": "AIA", "Name": "Anguilla", "IndepYear": null, "geography": {"Region": "Caribbean", "Continent": "North America", "SurfaceArea": 96}, "government": {"HeadOfState": "Elizabeth II", "GovernmentForm": "Dependent Territory of the UK"}, "demographics": {"Population": 8000, "LifeExpectancy": 76.0999984741211}}        00005de917d80000000000000003    {"type": "object"}
{"GNP": 3205, "_id": "00005de917d80000000000000004", "Code": "ALB", "Name": "Albania", "IndepYear": 1912, "geography": {"Region": "Southern Europe", "Continent": "Europe", "SurfaceArea": 28748}, "government": {"HeadOfState": "Rexhep Mejdani", "GovernmentForm": "Republic"}, "demographics": {"Population": 3401200, "LifeExpectancy": 71.5999984741211}}    00005de917d80000000000000004    {"type": "object"}
{"GNP": 1630, "_id": "00005de917d80000000000000005", "Code": "AND", "Name": "Andorra", "IndepYear": 1278, "geography": {"Region": "Southern Europe", "Continent": "Europe", "SurfaceArea": 468}, "government": {"HeadOfState": "", "GovernmentForm": "Parliamentary Coprincipality"}, "demographics": {"Population": 78000, "LifeExpectancy": 83.5}}      00005de917d80000000000000005    {"type": "object"}
{"GNP": 1941, "_id": "00005de917d80000000000000006", "Code": "ANT", "Name": "Netherlands Antilles", "IndepYear": null, "geography": {"Region": "Caribbean", "Continent": "North America", "SurfaceArea": 800}, "government": {"HeadOfState": "Beatrix", "GovernmentForm": "Nonmetropolitan Territory of The Netherlands"}, "demographics": {"Population": 217000, "LifeExpectancy": 74.69999694824219}}   00005de917d80000000000000006    {"type": "object"}
{"GNP": 37966, "_id": "00005de917d80000000000000007", "Code": "ARE", "Name": "United Arab Emirates", "IndepYear": 1971, "geography": {"Region": "Middle East", "Continent": "Asia", "SurfaceArea": 83600}, "government": {"HeadOfState": "Zayid bin Sultan al-Nahayan", "GovernmentForm": "Emirate Federation"}, "demographics": {"Population": 2441000, "LifeExpectancy": 74.0999984741211}}     00005de917d80000000000000007    {"type": "object"}
{"GNP": 340238, "_id": "00005de917d80000000000000008", "Code": "ARG", "Name": "Argentina", "IndepYear": 1816, "geography": {"Region": "South America", "Continent": "South America", "SurfaceArea": 2780400}, "government": {"HeadOfState": "Fernando de la Rúa", "GovernmentForm": "Federal Republic"}, "demographics": {"Population": 37032000, "LifeExpectancy": 75.0999984741211}}    00005de917d80000000000000008    {"type": "object"}
{"GNP": 1813, "_id": "00005de917d80000000000000009", "Code": "ARM", "Name": "Armenia", "IndepYear": 1991, "geography": {"Region": "Middle East", "Continent": "Asia", "SurfaceArea": 29800}, "government": {"HeadOfState": "Robert Kotšarjan", "GovernmentForm": "Republic"}, "demographics": {"Population": 3520000, "LifeExpectancy": 66.4000015258789}}        00005de917d80000000000000009    {"type": "object"}
......

    countrylanguage.txt:

[oracle@classroom ~]$ head -n 10 countrylanguage.txt
ABW     Dutch   T       5.3
ABW     English F       9.5
ABW     Papiamento      F       76.7
ABW     Spanish F       7.4
AFG     Balochi F       0.9
AFG     Dari    T       32.1
AFG     Pashto  T       52.4
AFG     Turkmenian      F       1.9
AFG     Uzbek   F       8.8
AGO     Ambo    F       2.4
......

    在MySQL 9.6数据库中,描述这些表的结构。将根据这些表结构的信息,在Oracle数据库中创建相应的表:

mysql> desc city;
+-------------+----------+------+-----+---------+----------------+
| Field       | Type     | Null | Key | Default | Extra          |
+-------------+----------+------+-----+---------+----------------+
| ID          | int      | NO   | PRI | NULL    | auto_increment |
| Name        | char(35) | NO   |     |         |                |
| CountryCode | char(3)  | NO   |     |         |                |
| District    | char(20) | NO   |     |         |                |
| Info        | json     | YES  |     | NULL    |                |
+-------------+----------+------+-----+---------+----------------+
5 rows in set (0.003 sec)

mysql> desc country;
+---------+----------+------+-----+---------+-------+
| Field   | Type     | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| Code    | char(3)  | NO   | PRI |         |       |
| Name    | char(52) | NO   |     |         |       |
| Capital | int      | YES  |     | NULL    |       |
| Code2   | char(2)  | NO   |     |         |       |
+---------+----------+------+-----+---------+-------+
4 rows in set (0.003 sec)

mysql> desc countryinfo;
+--------------+---------------+------+-----+---------+-------------------+
| Field        | Type          | Null | Key | Default | Extra             |
+--------------+---------------+------+-----+---------+-------------------+
| doc          | json          | YES  |     | NULL    |                   |
| _id          | varbinary(32) | NO   | PRI | NULL    | STORED GENERATED  |
| _json_schema | json          | YES  |     | NULL    | VIRTUAL GENERATED |
+--------------+---------------+------+-----+---------+-------------------+
3 rows in set (0.003 sec)

mysql> desc countrylanguage;
+-------------+---------------+------+-----+---------+-------+
| Field       | Type          | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| CountryCode | char(3)       | NO   | PRI |         |       |
| Language    | char(30)      | NO   | PRI |         |       |
| IsOfficial  | enum('T','F') | NO   |     | F       |       |
| Percentage  | decimal(4,1)  | NO   |     | 0.0     |       |
+-------------+---------------+------+-----+---------+-------+
4 rows in set (0.003 sec)

2. 在Oracle数据库中创建以上的表,并导入数据

2.1 根据MySQL 9.6数据库中的表结构信息,在Oracle数据库中创建相应的表:
    注意:Oracle数据库中由于字符集编码不同,char类型应该比MySQL数据库中适当加大:

[oracle@classroom ~]$ sqlplus /nolog

SQL*Plus: Release 19.0.0.0.0 - Production on Mon Mar 30 05:11:58 2026
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

SQL> conn hr/oracle_4U
Connected.
SQL> CREATE TABLE CITY ( ID NUMBER DEFAULT null , 
  2  NAME CHAR(50)  not null , COUNTRYCODE CHAR(3) not null, DISTRICT CHAR(100) not null, 
  3  INFO CLOB DEFAULT null , CHECK (Info is json)  , PRIMARY KEY (ID)  );

Table created.

SQL> create table country(Code char(3) not null,
  2  Name char(52) not null,
  3  Capital int default null, Code2 char(2) not null, 
  4  primary key(Code));

Table created.

SQL> create table countryinfo(doc clob DEFAULT null , CHECK (doc is json),
  2  id raw(32) default null,
  3  json_schema clob default null ,check(json_schema is json) , primary key(id));

Table created.

SQL>  create table countrylanguage(CountryCode char(3) not null,
  2  Language char(30) not null, IsOfficial char(1) not null, Percentage decimal(4,1) not null,
  3  check(IsOfficial in ('T','F')),primary key(CountryCode,Language));

Table created.

    从以上的代码看出:对于MySQL数据库的json列类型,Oracle数据库的对应类型是clob并配合check(is json)约束。对于MySQL数据库的varbinary列类型,Oracle数据库的对应类型是raw。对于MySQL数据库的enmu('T','F')列类型,Oracle数据库的对应的类型是char(1)并配合check(in 'T','F')约束。

2.2 编写用于进行SQLLOADER的控制文件:
    city.ctl:
    有一些列在文本中没有值,所以在控制文件中要加上“TRAILING NULLCOS”:

LOAD DATA
infile 'city.txt'
APPEND
INTO TABLE HR.CITY
FIELDS TERMINATED BY X'09' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
  ID INTEGER EXTERNAL,
  NAME CHAR,
  COUNTRYCODE CHAR,
  DISTRICT CHAR,
  INFO CHAR
)

    country.ctl:
    有一些列在文本中的CAPITAL列对应的位置, 本应该是整数值却是“\N”。这种行共有7行,所以需要先做替换:

[oracle@classroom ~]$ sed 's/\\N/0/g' country.txt > country2.txt

LOAD DATA
infile 'country2.txt'
APPEND
INTO TABLE HR.COUNTRY
FIELDS TERMINATED BY X'09' OPTIONALLY ENCLOSED BY '"'
(
  CODE CHAR,
  NAME CHAR,
  CAPITAL INTEGER EXTERNAL,
  CODE2 CHAR
)

    countryinfo表中,由于存在raw类型的列,所以不适合使用SQLLOADER进行加载数据。需要使用本博客下一节(2.3节)的外部表方式来加载。
     countrylanguage.ctl:

LOAD DATA
infile 'countrylanguage.txt'
APPEND
INTO TABLE HR.COUNTRYLANGUAGE
FIELDS TERMINATED BY X'09' OPTIONALLY ENCLOSED BY '"'
(
  COUNTRYCODE CHAR,
  LANGUAGE CHAR,
  ISOFFICIAL CHAR,
  PERCENTAGE INTEGER EXTERNAL
)

2.3 导入数据到Oracle数据库相应的表中
2.3.1 导入city表:

[oracle@classroom ~]$ sqlldr hr/oracle_4U control=city.ctl

SQL*Loader: Release 19.0.0.0.0 - Production on Thu Apr 2 05:52:41 2026
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Path used:      Conventional
Commit point reached - logical record count 250
Commit point reached - logical record count 500
Commit point reached - logical record count 750
Commit point reached - logical record count 1000
Commit point reached - logical record count 1250
Commit point reached - logical record count 1500
Commit point reached - logical record count 1750
Commit point reached - logical record count 2000
Commit point reached - logical record count 2250
Commit point reached - logical record count 2500
Commit point reached - logical record count 2750
Commit point reached - logical record count 3000
Commit point reached - logical record count 3250
Commit point reached - logical record count 3500
Commit point reached - logical record count 3750
Commit point reached - logical record count 4000
Commit point reached - logical record count 4074

Table HR.CITY:
  4074 Rows successfully loaded.

Check the log file:
  city.log
for more information about the load.

    city表加载操作的日志:

SQL*Loader: Release 19.0.0.0.0 - Production on Thu Apr 2 05:52:41 2026
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Control File:   city.ctl
Data File:      city.txt
  Bad File:     city.bad
  Discard File:  none specified

 (Allow all discards)

Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array:     250 rows, maximum of 1048576 bytes
Continuation:    none specified
Path used:      Conventional

Table HR.CITY, loaded from every logical record.
Insert option in effect for this table: APPEND
TRAILING NULLCOLS option in effect

   Column Name                  Position   Len  Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
ID                                  FIRST     *  WHT O(") CHARACTER
NAME                                 NEXT     *  WHT O(") CHARACTER
COUNTRYCODE                          NEXT     *  WHT O(") CHARACTER
DISTRICT                             NEXT     *  WHT O(") CHARACTER
INFO                                 NEXT     *  WHT O(") CHARACTER


Table HR.CITY:
  4074 Rows successfully loaded.
  0 Rows not loaded due to data errors.
  0 Rows not loaded because all WHEN clauses were failed.
  0 Rows not loaded because all fields were null.


Space allocated for bind array:                 324500 bytes(250 rows)
Read   buffer bytes: 1048576

Total logical records skipped:          0
Total logical records read:          4074
Total logical records rejected:         0
Total logical records discarded:        0

Run began on Thu Apr 02 05:52:41 2026
Run ended on Thu Apr 02 05:52:41 2026

Elapsed time was:     00:00:00.62
CPU time was:         00:00:00.11

2.3.2 导入country表:

[oracle@classroom ~]$ sqlldr hr/oracle_4U control=country.ctl

SQL*Loader: Release 19.0.0.0.0 - Production on Tue Mar 31 22:43:27 2026
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Path used:      Conventional
Commit point reached - logical record count 239

Table HR.COUNTRY:
  239 Rows successfully loaded.

Check the log file:
  country.log
for more information about the load.

    country表加载操作的日志:

SQL*Loader: Release 19.0.0.0.0 - Production on Thu Apr 2 19:26:25 2026
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Control File:   country.ctl
Data File:      country2.txt
  Bad File:     country2.bad
  Discard File:  none specified

 (Allow all discards)

Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array:     250 rows, maximum of 1048576 bytes
Continuation:    none specified
Path used:      Conventional

Table HR.COUNTRY, loaded from every logical record.
Insert option in effect for this table: APPEND
TRAILING NULLCOLS option in effect

   Column Name                  Position   Len  Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
CODE                                FIRST     *  WHT O(") CHARACTER
NAME                                 NEXT     *  WHT O(") CHARACTER
CAPITAL                              NEXT     *  WHT O(") CHARACTER
CODE2                                NEXT     *  WHT O(") CHARACTER


Table HR.COUNTRY:
  239 Rows successfully loaded.
  0 Rows not loaded due to data errors.
  0 Rows not loaded because all WHEN clauses were failed.
  0 Rows not loaded because all fields were null.


Space allocated for bind array:                 258000 bytes(250 rows)
Read   buffer bytes: 1048576

Total logical records skipped:          0
Total logical records read:           239
Total logical records rejected:         0
Total logical records discarded:        0

Run began on Thu Apr 02 19:26:25 2026
Run ended on Thu Apr 02 19:26:25 2026

Elapsed time was:     00:00:00.07
CPU time was:         00:00:00.02

2.3.3 使用外部表方式,导入countryinfo表:
    创建目录对象:

[oracle@classroom ~]$ mkdir dir1
[oracle@classroom ~]$ mv countryinfo.txt dir1
[oracle@classroom ~]$ sqlplus /nolog

SQL*Plus: Release 19.0.0.0.0 - Production on Tue Mar 31 23:04:23 2026
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

SQL> conn / as sysdba
Connected.
SQL> create directory dir1 as '/home/oracle/dir1';

Directory created.

SQL> grant all on  directory dir1 to hr; 

Grant succeeded.

    创建外部表:

[oracle@classroom ~]$ sqlplus /nolog

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Apr 1 04:54:34 2026
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

SQL> conn hr/oracle_4U
Connected.
SQL> CREATE TABLE countryinfo_ext (
  2   doc clob,
  3    id char(64),
  4    json_schema clob
  5  )
  6  ORGANIZATION EXTERNAL (
  7    TYPE ORACLE_LOADER
  8    DEFAULT DIRECTORY DIR1
  9    ACCESS PARAMETERS (
 10      RECORDS DELIMITED BY NEWLINE
 11      FIELDS TERMINATED BY X'09'
 12      MISSING FIELD VALUES ARE NULL
 13      (
 14        doc   char(2000),
 15        id   CHAR(64),   
 16        json_schema   char(2000)
 17      )    
 18      )
 19    LOCATION ('countryinfo.txt') 
 20  );

Table created.

    从上面的创建外部表的代码可以看出:在外部表中,先把raw(32)类型处理成char(64)。这是由于为了读取十六进制raw类型,字符串长度需要翻倍。然后通过insert ...select方式将外部表中的数据加载到内部表,同时作HEXTORAW转换:

SQL> insert into countryinfo 
  2  SELECT doc, HEXTORAW(trim(id)) , json_schema FROM countryinfo_ext;

239 rows created.

SQL> commit;

Commit complete.

    countryinfo_ext外部表加载操作的日志(在目录对象里,每次查询外部表都会产生一个日志):

[oracle@classroom ~]$ cd dir1
[oracle@classroom dir1]$ ls -ltr
total 160
-rw-r--r-- 1 oracle oinstall 97654 Mar 30 23:01 countryinfo.txt
-rw-r--r-- 1 oracle asmadmin   761 Mar 31 23:34 COUNTRYINFO_EXT_712396.log
-rw-r--r-- 1 oracle asmadmin  1522 Apr  1 05:03 COUNTRYINFO_EXT_812294.log
-rw-r--r-- 1 oracle asmadmin 38891 Apr  1 05:08 COUNTRYINFO_EXT_815582.log
-rw-r--r-- 1 oracle asmadmin  8302 Apr  1 05:28 COUNTRYINFO_EXT_817347.log
-rw-r--r-- 1 oracle asmadmin   754 Apr  1 22:00 COUNTRYINFO_EXT_1107323.log
[oracle@classroom dir1]$ cat COUNTRYINFO_EXT_1107323.log


 LOG file opened at 04/01/26 22:00:18

Total Number of Files=1

Data File: countryinfo.txt

Log File: COUNTRYINFO_EXT_1107323.log



 LOG file opened at 04/01/26 22:00:18

Bad File: COUNTRYINFO_EXT_1107323.bad

Field Definitions for table COUNTRYINFO_EXT
  Record format DELIMITED BY NEWLINE
  Data in file has same endianness as the platform
  Rows with all null fields are accepted

  Fields in Data Source: 

    DOC                             CHAR (2000)
      Terminated by "09"
      Trim whitespace same as SQL Loader
    ID                              CHAR (64)
      Terminated by "09"
      Trim whitespace same as SQL Loader
    JSON_SCHEMA                     CHAR (2000)
      Terminated by "09"
      Trim whitespace same as SQL Loader

2.3.4 导入countrylanguage表:

[oracle@classroom ~]$ sqlldr hr/oracle_4U control=countrylanguage.ctl

SQL*Loader: Release 19.0.0.0.0 - Production on Thu Apr 2 00:26:49 2026
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Path used:      Conventional
Commit point reached - logical record count 250
Commit point reached - logical record count 500
Commit point reached - logical record count 750
Commit point reached - logical record count 984

Table HR.COUNTRYLANGUAGE:
  984 Rows successfully loaded.

Check the log file:
  countrylanguage.log
for more information about the load.

    countrylanguage表加载操作的日志:

SQL*Loader: Release 19.0.0.0.0 - Production on Thu Apr 2 00:26:49 2026
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Control File:   countrylanguage.ctl
Data File:      countrylanguage.txt
  Bad File:     countrylanguage.bad
  Discard File:  none specified

 (Allow all discards)

Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array:     250 rows, maximum of 1048576 bytes
Continuation:    none specified
Path used:      Conventional

Table HR.COUNTRYLANGUAGE, loaded from every logical record.
Insert option in effect for this table: APPEND

   Column Name                  Position   Len  Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
COUNTRYCODE                         FIRST     *  WHT O(") CHARACTER
LANGUAGE                             NEXT     *  WHT O(") CHARACTER
ISOFFICIAL                           NEXT     *  WHT O(") CHARACTER
PERCENTAGE                           NEXT     *  WHT O(") CHARACTER


Table HR.COUNTRYLANGUAGE:
  984 Rows successfully loaded.
  0 Rows not loaded due to data errors.
  0 Rows not loaded because all WHEN clauses were failed.
  0 Rows not loaded because all fields were null.


Space allocated for bind array:                 258000 bytes(250 rows)
Read   buffer bytes: 1048576

Total logical records skipped:          0
Total logical records read:           984
Total logical records rejected:         0
Total logical records discarded:        0

Run began on Thu Apr 02 00:26:49 2026
Run ended on Thu Apr 02 00:26:51 2026

Elapsed time was:     00:00:01.77
CPU time was:         00:00:00.03

2.4 在Oracle数据库数据库中,查看导出是否成功
    city表在MySQL数据库中:

mysql> select  count(*) from city;
+----------+
| count(*) |
+----------+
|     4074 |
+----------+
1 row in set (0.002 sec)

    city表在Oracle数据库中:

SQL> select count(*) from city;

  COUNT(*)
----------
      4074

    country表在MySQL数据库中

mysql>  select  count(*) from country;
+----------+
| count(*) |
+----------+
|      239 |
+----------+
1 row in set (0.002 sec)

    country表在Oracle数据库中

SQL> select count(*) from country;

  COUNT(*)
----------
       239

    countryinfo表在MySQL数据库中

mysql> select  count(*) from countryinfo;
+----------+
| count(*) |
+----------+
|      239 |
+----------+
1 row in set (0.002 sec)

    countryinfo表在Oracle数据库中

SQL> select count(*) from countryinfo;

  COUNT(*)
----------
       239

    countrylanguage表在MySQL数据库中

mysql> select  count(*) from countrylanguage;
+----------+
| count(*) |
+----------+
|      984 |
+----------+
1 row in set (0.001 sec)

    countrylanguage表在Oracle数据库中

SQL> select count(*) from countrylanguage;

  COUNT(*)
----------
       984


路过

雷人

握手

鲜花

鸡蛋

QQ|手机版|Bo's Oracle Station   

GMT+8, 2026-4-2 15:42 , Processed in 0.062067 second(s), 21 queries .

返回顶部