简体   繁体   中英

how to read a tab delimited .txt file and insert into oracle table

I want to read a tab delimited file using PLSQL and insert the file data into a table. Everyday new file will be generated. I am not sure if external table will help here because filename will be changed based on date.

Filename: SPRReadResponse_YYYYMMDD.txt

Below is the sample file data.

在此处输入图像描述

Option that works on your own PC is to use SQL*Loader . As file name changes every day, you'd use your operating system's batch script (on MS Windows, these are.BAT files) to pass a different name while calling sqlldr (and the control file).

External table requires you to have access to the database server and have (at least) read privilege on its directory which contains those.TXT files. Unless you're a DBA, you'll have to talk to them to provide environment. As of changing file name, you could use alter table... location which is rather inconvenient.

If you want to have control over it, use UTL_FILE ; yes, you still need to have access to that directory on the database server, but - writing a PL/SQL script, you can modify whatever you want, including file name.


Or, a simpler option, first rename input file to SPRReadResponse.txt , then load it and save yourself of all that trouble.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM