search
HomeDatabaseMysql TutorialOracle 11g 数据装载的几种方式

数据的装载: SQL*LOADER 外部表 导入/导出 SQL*LOADER: SQL*LOADER是一个Oracle工具,能够将数据从外部数据文件装载到数据库中

数据的装载:

Oracle 11g的数据装载的几种方式

SQL*LOADER:

SQL*LOADER是一个Oracle工具,,能够将数据从外部数据文件装载到数据库中。

运行SQL*LOADER的命令是sqlldr。

Sqlldr的两种使用方式:

1. 只使用一个控制文件,在这个控制文件中包含数据

2. 使用一个控制文件(作为模板) 和一个数据文件

一般采用第二种方式,数据文件可以是 CSV 文件、txt文件或者以其他分割符分隔的。

说明:操作类型 可用以下中的一值:

1) insert    --为缺省方式,在数据装载开始时要求表为空

2) append  --在表中追加新记录

3) replace  --删除旧记录(用 delete from table 语句),替换成新装载的记录

4) truncate --删除旧记录(用 truncate table 语句),替换成新装载的记录

通过spool来制作数据文件:--可以查询帮助文档的示例代码

SQL> spool /u01/app/oracle/test_data_loader/student.txt--开启spool导出数据文件
SQL> select id ||',' || name ||',' || age ||',' || inner_date from student;--导出数据

ID||','||NAME||','||AGE||','||INNER_DATE
--------------------------------------------------------------------------------
1,zhangsan,21,23-JAN-15
2,lisi,22,23-JAN-15
3,wangwu,23,23-JAN-15

SQL> spool off;--关闭
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost test_data_loader]$ cat student.txt--可以查看到导出的数据记录
SQL> select id ||',' || name ||',' || age ||',' || inner_date from student;

ID||','||NAME||','||AGE||','||INNER_DATE
--------------------------------------------------------------------------------
1,zhangsan,21,23-JAN-15
2,lisi,22,23-JAN-15
3,wangwu,23,23-JAN-15

SQL> spool off;

写配置文件:
[oracle@localhost test_data_loader]$ vi student.ctl
[oracle@localhost test_data_loader]$ cat student.ctl
options(skip=4)--表示前面的四行
load data--导入数据
infile 'student.txt'--通过该文件导入数据
into table student--导入的表
insert--执行的是插入操作
fields terminated by ','--记录中的分割符
(
id char,--注意虽然表中是number类型,但是要写char类型
name char,
age char,
inner_date date nullif (inner_date = "null"))
[oracle@localhost test_data_loader]$

既然是insert操作所以:
SQL> truncate table student;--清空表,由于执行的是插入操作

Table truncated.

SQL> select * from student;

no rows selected

执行sqlldr操作:
[oracle@localhost test_data_loader]$ sqlldr hr/hr control= student.ctl log = student.log

SQL*Loader: Release 11.2.0.1.0 - Production on Fri Jan 23 23:11:08 2015

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

Commit point reached - logical record count 4
[oracle@localhost test_data_loader]$ cat student.log

SQL*Loader: Release 11.2.0.1.0 - Production on Fri Jan 23 23:11:08 2015

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

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

(Allow all discards)

Number to load: ALL
Number to skip: 4
Errors allowed: 50
Bind array:    64 rows, maximum of 256000 bytes
Continuation:    none specified
Path used:      Conventional

Table STUDENT, loaded from every logical record.
Insert option in effect for this table: INSERT

  Column Name                  Position  Len  Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
ID                                  FIRST    *  ,      CHARACTER
NAME                                NEXT    *  ,      CHARACTER
AGE                                  NEXT    *  ,      CHARACTER
INNER_DATE                          NEXT    *  ,      DATE DD-MON-RR
    NULL if INNER_DATE = 0X6e756c6c(character 'null')

Record 4: Rejected - Error on table STUDENT, column ID.
Column not found before end of logical record (use TRAILING NULLCOLS)

Table STUDENT:
  3 Rows successfully loaded.
  1 Row 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:                  66048 bytes(64 rows)
Read  buffer bytes: 1048576

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you alter a table in MySQL using the ALTER TABLE statement?How do you alter a table in MySQL using the ALTER TABLE statement?Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

How do I configure SSL/TLS encryption for MySQL connections?How do I configure SSL/TLS encryption for MySQL connections?Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

How do you handle large datasets in MySQL?How do you handle large datasets in MySQL?Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you drop a table in MySQL using the DROP TABLE statement?How do you drop a table in MySQL using the DROP TABLE statement?Mar 19, 2025 pm 03:52 PM

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

How do you create indexes on JSON columns?How do you create indexes on JSON columns?Mar 21, 2025 pm 12:13 PM

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

How do you represent relationships using foreign keys?How do you represent relationships using foreign keys?Mar 19, 2025 pm 03:48 PM

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?Mar 18, 2025 pm 12:00 PM

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function