sql 加载器日志文件结果

发布于 2024-08-20 23:13:21 字数 179 浏览 9 评论 0原文

我在 ASP.NET 应用程序中使用 SQLloader 自动将数据从 CSV/EXCEL 批量上传到 Oracle 数据库。 Sqlloader 创建一个日志文件,显示在服务器上创建的导入结果。

我想向我的用户显示一些信息

读取了多少行? 有多少成功导入? 在 aspx 页面上

我该怎么做?

I am using SQLloader in ASP.NET appliaction to automate the bulk upload data to oracle db from CSV/EXCEL.
Sqlloader creates a log file that shows the result of import that is created on server.

I want to show some info to my users

How many rows read?
How many successfully imported?
on an aspx page

How do I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一刻暧昧 2024-08-27 23:13:21

您可以创建外部表来读取日志文件。这样做的好处是可以在 SQL 查询中使用外部表。

首先,您需要创建一个目录对象来标识操作系统目录路径。这需要由具有 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> 

接下来我们创建表。请注意位置子句中日志文件的占位符名称...

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>

现在到操作系统进行导入...

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 或更高版本,因此可以使用 Regex 函数。

You can create an external table to read the log files. The virtue of this is that external tables can be used in SQL queries.

Firstly you need to create a directory object to identify the OS directory path. This needs to be done by a user with the CREATE ANY DIRECTORY privilege (probably a DBA account)....

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> 

Next we create the table. Note the placeholder name for the logfile in the location clause....

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>

Now out to the OS to do an import ...

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>

This directory should be the same diectory you used before. Back into SQL. First we point the external table at the log file we used earlier and then query from it ...

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>

Formatting the output is easy, especially if you have 10g or higher, and so can use Regex functions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文