首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sql加载器日志文件结果

问sql加载器日志文件结果
EN

Stack Overflow用户
提问于 2010-02-04 18:45:03
回答 1查看 3.7K关注 0票数 2

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

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

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

我该怎么做?

EN

回答 1

Stack Overflow用户

发布于 2010-02-04 20:18:41

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

首先,您需要创建一个目录对象来标识OS目录路径。这需要由具有CREATE ANY DIRECTORY权限(可能是DBA帐户)的用户完成。

代码语言:javascript
复制
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子句中日志文件的占位符名称...

代码语言:javascript
复制
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>

现在到操作系统去做一个导入...

代码语言:javascript
复制
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。首先,我们将外部表指向之前使用的日志文件,然后从其中进行查询……

代码语言:javascript
复制
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函数。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2198987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档