« 用OCI 8实现了sqluldr2 »
Tools » http://www.anysql.net/tools/sqluldr2_comming.html 2009-03-27有同事需要将包含LOB列的数据导出成文本文件, 用OCI 7接口写的第一版sqluldr或ociuldr在处理LOB列时(LONG列没有这个问题)遇到了一些不能克服的问题. 在10g的数据库上导出时, 如果LOB列有NULL值或空LOB值, 会出现ORA-32255错误. 对这个错误号, 找遍了Google和Metalink都没有解决方案. 错误信息如下所示.
D:\>sqluldr parfile=testpar.txt
0 rows exported at 2009-03-27 19:18:19
ORA-32255: Message 32255 not found; product=RDBMS; facility=ORA
9 rows exported at 2009-03-27 19:18:19
output file uldrdata.txt closed at 9 rows.
如果数据库是9i, 并且没有打过较新的补丁, 则程序会挂起, 这个是已知的Bug.
D:\>sqluldr parfile=testpar.txt
0 rows exported at 2009-03-27 19:18:19
按OCI 8接口格式重写的sqluldr2就没有这个问题, 能顺利导出.
D:\>sqluldr2 parfile=testpar.txt
0 rows exported at 2009-03-27 19:18:13
9 rows exported at 2009-03-27 19:18:13
output file uldrdata.txt closed at 9 rows.
重写后的版本性能上好象比第一版略有提高, 导出成逗号分隔的文件用的时间为:
D:\>sqluldr2 parfile=testpar.txt array=500
0 rows exported at 2009-03-27 19:19:12
500000 rows exported at 2009-03-27 19:19:15
1000000 rows exported at 2009-03-27 19:19:18
1500000 rows exported at 2009-03-27 19:19:22
2000000 rows exported at 2009-03-27 19:19:25
2500000 rows exported at 2009-03-27 19:19:29
3000000 rows exported at 2009-03-27 19:19:32
3500000 rows exported at 2009-03-27 19:19:35
3670044 rows exported at 2009-03-27 19:19:37
output file uldrdata.txt closed at 3670044 rows.
导出成固定长度格式的文件用的时间为:
D:\>sqluldr2 parfile=testpar.txt array=500 field=0×20
0 rows exported at 2009-03-27 19:19:45
500000 rows exported at 2009-03-27 19:19:48
1000000 rows exported at 2009-03-27 19:19:51
1500000 rows exported at 2009-03-27 19:19:55
2000000 rows exported at 2009-03-27 19:19:59
2500000 rows exported at 2009-03-27 19:20:03
3000000 rows exported at 2009-03-27 19:20:06
3500000 rows exported at 2009-03-27 19:20:10
3670044 rows exported at 2009-03-27 19:20:11
output file uldrdata.txt closed at 3670044 rows.
实际上花了两个小时重写, 比我以前预计的要简单一些, 可下载两个版本的程序进行测试.


windows上fopen/fread有2g限制,不知道是否用CreateFIle好一些,内存映射文件有帮助吗
Windows上没有2G的限制吧?
我记错了,是4G限制
#ifndef _SIZE_T_DEFINED
typedef unsigned int size_t;
#define _SIZE_T_DEFINED
#endif
_CRTIMP size_t __cdecl fread(void *, size_t, size_t, FILE *);
访问不能超过2^32
BOOL WINAPI GetFileSizeEx(
__in HANDLE hFile,
__out PLARGE_INTEGER lpFileSize
);
Parameters
hFile [in]
A handle to the file. The handle must have been created with either the GENERIC_READ or GENERIC_WRITE access right. For more information, see File Security and Access Rights.
lpFileSize [out]
A pointer to a LARGE_INTEGER structure that receives the file size, in bytes.
LARGE_INTEGER Union
The LARGE_INTEGER structure is used to represent a 64-bit signed integer value.
Note Your C compiler may support 64-bit integers natively. For example, Microsoft Visual C++ supports the __int64 sized integer type. For more information, see the documentation included with your C compiler.
Syntax
typedef union _LARGE_INTEGER { struct { DWORD LowPart; LONG HighPart; } ; struct { DWORD LowPart; LONG HighPart; } u; LONGLONG QuadPart;
} LARGE_INTEGER, *PLARGE_INTEGER;
fread参数有两个大小单位,第一个是记录长度,第二个是读取的记录数,结合起来,可以超过2GB的。
对于文本导出来说, 我只写出,应当是可以超出4GB的,我手头上没有这么大的表,应当测试一下。
为什么不用Windows的函数, 是因为这个程序还要在其他平台上编译,所以只用标准C函数。
Widnwos下fpos_t这个是一个8字节的整数,是64位的,用fsetpos来设置文件位置, 然后读取内容。
ORA-00932: 数据类型不一致: 应为 CHAR, 但却获得 BLOB
我在导出的时候报这个错。我本机windows xp ,客户端10G,服务器也是10G,请问下这个是不能导出lob字段啊?
Show一下你的表结构? 我测试一下.