我正在下载/更新
大约4,000个csv文件包含
库存数据(开盘/高/低/收盘/成交量)
到一个目录“文件夹”
csv文件每天更新,
每天早上都会添加新数据,
有时现有数据得到纠正。 (我正在使用CsiData的Unfair Advantage,它可以纠正以前不正确的数据。)
我想在“文件夹”中“csv文件”
要自动导入我的“Oracle数据库”,
在指定的时间。
答案 0 :(得分:1)
假设该文件夹可通过oracle访问,并且您具有查看该文件夹的正确权限 以下是所需代码(未经测试)的粗略指南,请参阅Ask Tom
CREATE TABLE files_to_process (file_name VARCHAR2(255));
CREATE OR REPLACE
AND COMPILE JAVA SOURCE NAMED "DirectoryList"
AS
import java.io.*;
import java.sql.*;
public class DirectoryList
{
public static void ListAllFiles(String directory)
throws SQLException
{
File path = new File( directory );
String[] list = path.list();
String element;
for(int i = 0; i < list.length; i++)
{
element = list[i];
sql
{
INSERT INTO Files_to_process (FILENAME) VALUES (:element)
};
}
}
}
/
CREATE OR REPLACE PROCEDURE get_files_to_process( p_directory in varchar2 )
AS LANGUAGE JAVA
NAME 'DirectoryList.ListAllFiles( java.lang.String )';
/
BEGIN
delete Files_to_process;
get_files_to_process( '\mnt\your_folder' );
for rec in (select file_name from Files_to_process)
LOOP
process_file(file_name);
END LOOP;
END;
--so the procedure below can open the files......
CREATE OR REPLACE DIRECTORY in_files as '\mnt\your_folder';
create table stock_file_to_process as
(
--your csv structure here
--STOCKID number,
--Open number,
--High number,
--Low number,
--Close number,
--Volume number
)
ORGANIZATION EXTERNAL
( type oracle_loader
default directory in_files
access parameters
( fields terminated by ',' )
location ('emp.dat')
)
/
CREATE PROCEDURE process_file(p_filename varchar2(255)) as
BEGIN
execute immediate 'ALTER TABLE file_to_process LOCATION( p_filename )';
for rec in (select Stockid,Open,High,Low,Close,Volume from stock_file_to_process)
LOOP
--your processing code here
END LOOP;
END;