'Note that this code fragment assumes an orablob object as the result of a 
'dynaset operation. This object could have been an OUT parameter of a PL/SQL 
'procedure. For more information please refer to chapter 1. there are two ways 
'of writing a lob using  orablob.write or orablob.copyfromfile

'Using OraBlob.Write mechanism
Dim MySession As OraSession
Dim OraDb As OraDatabase
Dim fnum As Integer
Dim OraDyn As OraDynaset, OraSound As OraBlob, amount_written%, chunksize%, curchunk() As Byte

Set MySession = CreateObject("OracleInProcServer.XOraSession")
Set OraDb = MySession.OpenDatabase("exampledb", "samp/samp", 0&)
chunksize = 500
ReDim curchunk(chunksize)
Set OraDyn = OraDb.CreateDynaset("SELECT * FROM Multimedia_tab", ORADYN_DEFAULT)
Set OraSound = OraDyn.Fields("Sound").Value

fnum = FreeFile

Open "c:\tmp\washington_audio" For Binary As #fnum
OraSound.offset = 1
OraSound.pollingAmount = LOF(fnum)
remainder = LOF(fnum)

 Dim piece As Byte
 Get #fnum, , curchunk
 OraDyn.Edit

 piece = ORALOB_FIRST_PIECE
 OraSound.Write curchunk, chunksize, ORALOB_FIRST_PIECE

 While OraSound.Status = ORALOB_NEED_DATA
    remainder = remainder - chunksize
    If remainder <= chunksize Then
        chunksize = remainder
        piece = ORALOB_LAST_PIECE
    Else
        piece = ORALOB_NEXT_PIECE
    End If

    Get #fnum, , curchunk
    OraSound.Write curchunk, chunksize, piece
 Wend

OraDyn.Update

'Using OraBlob.CopyFromFile mechanism
Set OraDyn = OraDb.CreateDynaset("select * from Multimedia_tab order by clip_id", ORADYN_DEFAULT)
Set OraSound = OraDyn.Fields("Sound").Value
OraDyn.Edit
OraSound.CopyFromFile "c:\tmp\washington_audio"
OraDyn.Update
