ASP.NET アプリケーションで SQLloader を使用して、CSV/EXCEL から oracle db へのデータの一括アップロードを自動化しています。Sqlloader は、サーバー上で作成されたインポートの結果を示すログ ファイルを作成します。
ユーザーに情報を表示したい
何行読んだ?正常にインポートされた数は? aspx ページで
それ、どうやったら出来るの?
ASP.NET アプリケーションで SQLloader を使用して、CSV/EXCEL から oracle db へのデータの一括アップロードを自動化しています。Sqlloader は、サーバー上で作成されたインポートの結果を示すログ ファイルを作成します。
ユーザーに情報を表示したい
何行読んだ?正常にインポートされた数は? aspx ページで
それ、どうやったら出来るの?
ログ ファイルを読み取るための外部テーブルを作成できます。これの利点は、SQL クエリで外部テーブルを使用できることです。
まず、OS ディレクトリ パスを識別するディレクトリ オブジェクトを作成する必要があります。これは、CREATE ANY DIRECTORY 権限を持つユーザー (おそらく DBA アカウント) が行う必要があります。
SQL> create or replace directory sqlldr_log_dir as 'C:\your\directory\path'
2 /
Directory created.
SQL> grant read , write on directory sqlldr_log_dir to apc
2 /
Grant succeeded.
SQL>
次に、テーブルを作成します。location 節のログファイルのプレースホルダー名に注意してください....
SQL> create table sqlldr_logfiles (
2 text_line varchar2(1024)
3 )
4 organization external
5 (
6 type oracle_loader
7 default directory sqlldr_log_dir
8 access parameters
9 (records delimited by newline
10 fields (text_line char(1024)
11 )
12 )
13 location ('changeme.log')
14 )
15 /
Table created.
SQL>
インポートを行うためにOSに出て...
C:\temp>imp apc file=apc_20100204.dmp log=apc_20100204.log tables=PTEST6,A
Import: Release 11.1.0.6.0 - Production on Thu Feb 4 11:51:07 2010
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Password:
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V11.01.00 via conventional path
import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
. importing APC's objects into APC
. importing APC's objects into APC
. . importing table "A" 12 rows imported
. . importing table "PTEST6" 19 rows imported
IMP-00009: abnormal end of export file
Import terminated successfully with warnings.
C:\temp>
このディレクトリは、以前に使用したディレクトリと同じである必要があります。SQL に戻ります。最初に、以前に使用したログ ファイルで外部テーブルをポイントし、そこからクエリを実行します ...
SQL> alter table sqlldr_logfiles location ('apc_20100204.log')
2 /
Table altered.
SQL> select * from sqlldr_logfiles
2 where text_Line like '. . importing table%'
3 /
text_Line
--------------------------------------------------------------------------------
. . importing table "A" 12 rows imported
. . importing table "PTEST6" 19 rows imported
SQL>
出力のフォーマットは簡単です。特に 10g 以上の場合は、正規表現関数を使用できます。