私は、Python 3.6を使用してフォルダ構造を反復し、これらのCSVのファイル・パスを、すでに作成された2つのOracle表にインポートします。CSVをOracle表(Python)に効率的にインポートする
con = cx_Oracle.connect('BLAH/[email protected]:666/BLAH')
#Targets the exact filepaths of the CSVs we want to import into the Oracle database
if os.access(base_cust_path, os.W_OK):
for path, dirs, files in os.walk(base_cust_path):
if "Daily" not in path and "Daily" not in dirs and "Jul" not in path and "2017-07" not in path:
for f in files:
if "OUTPUT" in f and "MERGE" not in f and "DD" not in f:
print("Import to OUTPUT table: "+ path + "/" + f)
#Run function to import to SQL Table 1
if "MERGE" in f and "OUTPUT" not in f and "DD" not in f:
print("Import to MERGE table: "+ path + "/" + f)
#Run function to import to SQL Table 2
しばらく前に私は、SQL ServerのBULKのINSERTのSQLコマンドを使用する機能を生成するためにPHPを使用することができました:
function bulkInserttoDB($csvPath){
$tablename = "[DATABASE].[dbo].[TABLE]";
$insert = "BULK
INSERT ".$tablename."
FROM '".$csvPath."'
WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\\n')";
print_r($insert);
print_r("<br>");
$result = odbc_prepare($GLOBALS['connection'], $insert);
odbc_execute($result)or die(odbc_error($connection));
}
私は、Pythonのためにこれを複製するために探しているが、いくつかのましたGoogle検索の結果、Oracle用に「BULK INSERT」コマンドがないと思われました。このBULK INSERTコマンドは素晴らしいパフォーマンスを実現しました。
私がロードしているこれらのCSVは巨大(2GB×365)なので、パフォーマンスが重要です。これを行う最も効率的な方法は何ですか?
[sql * loader](https://stackoverflow.com/a/6198961/322909)+ pythonのPopenを使用することをお勧めします。 – John
Oracle Data Pumpを使用してデータをロードします。 –