Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Batch data files import data to oracle with sqlldrr

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Many people must have used sqlload to direct text data to oracle, but if there are hundreds or thousands of data text, or text data is generated in real time. How to import oracle in bulk for this scenario? here's how I deal with it.

The 1.shell script LoadData.sh is as follows

#! / bin/bashdata_dir=/home/bea/datasource/warn-log/dayflow # text data directory data_dir_bak=/home/bea/datasource/warn-log/dayflow_bakshell_dir=/home/bea/scriptwhile [1] docd $data_dirif [`pwd` = = $data_dir] then filelist= `ls-rt | grep dayflow.log_. `# data text file name matches fi#echo $filelistcd $shell_dirif [`pwd` = = $shell_dir] then for file in $filelist do date= `date "+% Y%m%d% H:%M:%S" `export LoadFileName=$data_dir "/" $file # is very important To load variables into the environment echo "Time is $date, start importing $LoadFileName data" sqlldr user_1/123456@213_db control=dayflow.log.ctl BAD=dayflow.log.bad echo "Time is $date, $LoadFileName data import" echo "start backing up the file $file" mv $LoadFileName $data_dir_bak echo "$file backup" donefidone

The most important thing to pay attention to in this place is

Export LoadFileName=$data_dir "/" $file

Here, the variable LoadFileName (text imported into oracle, absolute path) is export into the linux environment, so that the control file of sqlload can read the variable and import it.

2.sqlldr controls text dayflow.log.ctl

Load dataCHARACTERSET AL32UTF8infile'$LoadFileName'APPEND into table user_1.BIL_FLUX_HIGH_CURfields terminated by'| 'trailing nullcols (ACCS_NBR "TRIM (: ACCS_NBR)", DATE_ID "TRIM (: DATE_ID)", TOTAL_FLUX "TRIM (: TOTAL_FLUX)", sys_date "sysdate")

Please note that infile'$LoadFileName', here is the variable just export in shell. In this way, you can pass in the file name as a variable, so the batch import is a circular operation.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report