ORACLE导入TXT文件数据的解决思路
需求场景:data.txt源数据:[INFO]2012-12-0100:01:171610FHR行号=24.查看指定计划的钢卷数据.计划号=121200102.[INFO]2012-12-0100:03:131610FHR行号=24.查看指
需求场景:
data.txt源数据:
[INFO] 2012-12-01 00:01:17 1610 FHR "行号=24. 查看指定计划的钢卷数据. 计划号=121200102." [INFO] 2012-12-01 00:03:13 1610 FHR "行号=24. 查看指定计划的钢卷数据. 计划号=121200103." [INFO] 2012-12-01 00:20:21 7362 RICC "IntervalTime=0,RollingTime=0" [INFO] 2012-12-01 00:20:21 7363 RICC "WRTFMOff: 24.5, 24.8, 24.9, 25.1, 25.3, 25.3, 25.4, 26.5[C]." [INFO] 2012-12-01 00:20:21 7362 RICC "IntervalTime=0, RollingTime=0, WRTFMOff:fT=24.632685"
拿到这一份源数据后,第一眼我们看到像这种类型的数据就是应该使用sql*loader工具。把该源文件的数据导入到oracle数据库。
那么,我们先来熟悉一下这个工具:
一、sql*loader的概述
很多情况之下,我们的数据需要批量处理传输到库,或者在库之间批量传输数据。其中,常见
的情形是用从事务处理系统提取的数据填充数据仓库,或将数据从实时系统复制到测试开发环境。对
大规模操作而言,使用标准的INSERT语句插入数据并不总是最佳方式,而oracle本身附带了SQL*Loader和Data Pump功能来支持批量操作。通过使用外部表,还可以在不将数据插入数据库的情况下读取数据。
从体系结构上讲,SQL*Loader进程与其他用户进程类似:它通过服务器进程连接到数据库。
要插入行,可以采用两种技术:常规方式或直接路径读取。常规方式是使用INSERT。SQL*Loader用户进程构造values子句中包含绑定变量的insert语句,然后读取源数据文件,为每一个要插入的行执行
一次insert。此方法使用数据库缓冲区缓存,并生成撤销(undo)和重做数据(redo log),这些insert
语句与其他同类语句相似,通过普通的提交处理实现数据永久化。
直接路径是避开了database buffer,sql*loader读取源数据文件,并将内容发送到服务器进程。
此后,美国服务器,服务器进程在其PGA中组装表数据中的块,并将它们直接写入数据文件。写操作在表的高水位
线上完成,称为数据保存(data save)。高水位线是表段中的一个标记,其上未写入任何数据:高水
位线上的空间是分配给尚未使用的表的空间。加载完成后,服务器空间,sql*loader移动高水位线,免备案空间,从而包含最新
写入的数据块,并且其他用户都可以立即看见这些数据块内的行。上述操作相当于一个commit命令。
此时不会生成撤销,也可以主动的取消重做日志的生成。所以说,直接路径加载是很快捷的。
二、SQL*Loader直接路径缺点
直接路径也存在以下缺点:
1、执行操作期间,必须删除或禁用引用完整性约束(只能实施unique、primary key、not null约束)。
2、会将针对其他会话的DML锁定表
3、不会激活insert触发器
4、无法为群集表使用
sql*loader体系结构:
三、实际操作演示
好了,这里没办法说得太细节化,相关的知识大家自己补充。
新建一个测试表TEST(我们要把源数据导入这个表):
SQL>conn hr/oracle@testdb
SQL> create table test(
2 name varchar2(10),
3 indate varchar2(20),
4 intime varchar2(20),
5 num int,
6 source varchar2(10),
7 description varchar2(128)
8 );
准备好data.txt、data_test.ctl(加载所要使用的控制文件,定义数据规则的)
data_test.ctl:
sqlldr这个命令就是sql*loader工具,是在$ORACLE_HOME/bin目录下
C:\Documents and Settings\Administrator>sqlldr hr/oracle@testdb control=E:\oracle\exercises\data_test.ctl log=E:\oracle\exercises\data_test.log
3 小时前 上传
下载附件(39.43 KB)
查询下结果:
3 小时前 上传
下载附件(39.34 KB)
到此为止,提出的需求已经完成。关于控制文件里面的命令是什么意思,有时间的话下次解释一下或者留点给大家自己去学习吧。希望大家可以相互参与到讨论当中,相互提高自己!
本文出自 “海斌的技术博客” 博客,转载请与作者联系!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.
