这里有一段代码可以存取大文件的 存取大文件 存: Dim Chunk() As Byte If Imageabove.Tag < > " " Then 'Dim Chunk() As Byte Chunk() = Image2Chunk(tmpFile1) .Fields( "tp1 ").AppendChunk Chunk() .UpdateBatch adAffectCurrent End If Private Function Image2Chunk(Filename As String) As Variant On Error GoTo ProcErr Dim Datafile As Integer Dim FileLength As Long Dim Chunk() As Byte Datafile = FreeFile Open Filename For Binary Access Read As Datafile FileLength = LOF(Datafile) If FileLength = 0 Then GoTo ProcErr ReDim Chunk(FileLength) Get Datafile, , Chunk() Close Datafile
ProcExit: Image2Chunk = Chunk() Exit Function ProcErr: Image2Chunk = 0 End Function
取: If (rs.Fields( "tp1 ").ActualSize = 0) Then Image1.Picture = Nothing 'Exit Sub Else Dim Chunk() As Byte Chunk() = rs.Fields( "tp1 ").GetChunk(rs.Fields( "tp1 ").ActualSize) Set Image1.Picture = Chunk2Image(Chunk(), "temp.fil ") Image1.Tag = "hello " End If Public Function Chunk2Image(Chunk() As Byte, Optional Filename As String) As Variant On Error GoTo ProcErr Dim KeepFile As Boolean Dim Datafile As Integer KeepFile = True If Trim(Filename) = " " Then Filename = "c:\tmpxxdb.fil " KeepFile = False End If Datafile = FreeFile Open Filename For Binary Access Write As Datafile Put Datafile, , Chunk() Close Datafile ProcExit: Set Chunk2Image = LoadPicture(Filename) On Error Resume Next ' If Not KeepFile Then Kill filename Exit Function ProcErr: On Error Resume Next Kill Filename Chunk2Image = 0 End Function /*****************************************************************************/ 在internal这个用户下给scott用户授权如下: SQL >grant create any directory to scott; SQL >grant create any library to scott; 在scott这个用户下执行下述语句: SQL >create table bfile_tab (bfile_column BFILE); SQL >create table utl_lob_test (blob_column BLOB); SQL >create or replace directory utllobdir as 'C:\DDS\EXTPROC'; SQL >set serveroutput on 然后执行下面语句就将C:\DDS\EXTPROC目录下的word文件COM.doc存入到utl_lob_test 表中的blob_column字段中了。 declare a_blob BLOB; a_bfile BFILE := BFILENAME('UTLLOBDIR','COM.doc'); --用来指向外部操作系统 文件 begin insert into bfile_tab values (a_bfile) returning bfile_column into a_bfile; insert into utl_lob_test values (empty_blob()) returning blob_column into a_blob; dbms_lob.fileopen(a_bfile); dbms_lob.loadfromfile(a_blob, a_bfile, dbms_lob.getlength(a_bfile)); dbms_lob.fileclose(a_bfile); commit; end;
存取大文件
存: Dim Chunk() As Byte
If Imageabove.Tag < > " " Then
'Dim Chunk() As Byte
Chunk() = Image2Chunk(tmpFile1)
.Fields( "tp1 ").AppendChunk Chunk()
.UpdateBatch adAffectCurrent
End If Private Function Image2Chunk(Filename As String) As Variant
On Error GoTo ProcErr
Dim Datafile As Integer
Dim FileLength As Long
Dim Chunk() As Byte Datafile = FreeFile
Open Filename For Binary Access Read As Datafile
FileLength = LOF(Datafile)
If FileLength = 0 Then GoTo ProcErr
ReDim Chunk(FileLength)
Get Datafile, , Chunk()
Close Datafile
ProcExit:
Image2Chunk = Chunk()
Exit Function ProcErr:
Image2Chunk = 0
End Function
取:
If (rs.Fields( "tp1 ").ActualSize = 0) Then
Image1.Picture = Nothing
'Exit Sub
Else
Dim Chunk() As Byte
Chunk() = rs.Fields( "tp1 ").GetChunk(rs.Fields( "tp1 ").ActualSize)
Set Image1.Picture = Chunk2Image(Chunk(), "temp.fil ")
Image1.Tag = "hello "
End If
Public Function Chunk2Image(Chunk() As Byte, Optional Filename As String) As Variant
On Error GoTo ProcErr
Dim KeepFile As Boolean
Dim Datafile As Integer KeepFile = True
If Trim(Filename) = " " Then
Filename = "c:\tmpxxdb.fil "
KeepFile = False
End If Datafile = FreeFile
Open Filename For Binary Access Write As Datafile
Put Datafile, , Chunk()
Close Datafile ProcExit:
Set Chunk2Image = LoadPicture(Filename)
On Error Resume Next
' If Not KeepFile Then Kill filename
Exit Function ProcErr:
On Error Resume Next
Kill Filename
Chunk2Image = 0
End Function
/*****************************************************************************/
在internal这个用户下给scott用户授权如下:
SQL >grant create any directory to scott;
SQL >grant create any library to scott;
在scott这个用户下执行下述语句: SQL >create table bfile_tab (bfile_column BFILE);
SQL >create table utl_lob_test (blob_column BLOB);
SQL >create or replace directory utllobdir as 'C:\DDS\EXTPROC';
SQL >set serveroutput on 然后执行下面语句就将C:\DDS\EXTPROC目录下的word文件COM.doc存入到utl_lob_test
表中的blob_column字段中了。 declare
a_blob BLOB;
a_bfile BFILE := BFILENAME('UTLLOBDIR','COM.doc'); --用来指向外部操作系统 文件
begin
insert into bfile_tab values (a_bfile)
returning bfile_column into a_bfile;
insert into utl_lob_test values (empty_blob())
returning blob_column into a_blob;
dbms_lob.fileopen(a_bfile);
dbms_lob.loadfromfile(a_blob, a_bfile, dbms_lob.getlength(a_bfile));
dbms_lob.fileclose(a_bfile);
commit;
end;