12.API: LOB Objects
A LOB object can be created withConnection.createlob()
. SeeUsing CLOB, BLOB, NCLOB, and BFILE Data for more information about using LOBs.
This object is returned by default whenever OracleCLOB
,BLOB
andBFILE
columns are fetched.
12.1.LOB Methods
- LOB.close()
Closes the LOB. Call this when writing is completed so that the indexesassociated with the LOB can be updated – but only if
open()
was called first.
- LOB.fileexists()
Returns a boolean indicating if the file referenced by the BFILE type LOBexists.
- LOB.getchunksize()
Returns the chunk size for the internal LOB. Reading and writing to the LOBin chunks of multiples of this size will improve performance.
- LOB.getfilename()
Returns a two-tuple consisting of the directory alias and file name for aBFILE type LOB.
- LOB.open()
Opens the LOB for writing. This will improve performance when writing to aLOB in chunks and there are functional or extensible indexes associatedwith the LOB. If this method is not called, each write will perform an openinternally followed by a close after the write has been completed.
- LOB.read([offset=1[,amount]])
Returns a portion (or all) of the data in the LOB object. Note that theamount and offset are in bytes for BLOB and BFILE type LOBs and in UCS-2code points for CLOB and NCLOB type LOBs. UCS-2 code points are equivalentto characters for all but supplemental characters. If supplementalcharacters are in the LOB, the offset and amount will have to be chosencarefully to avoid splitting a character.
- LOB.setfilename(dir_alias,name)
Sets the directory alias and name of the BFILE type LOB.
- LOB.size()
Returns the size of the data in the LOB object. For BLOB and BFILE typeLOBs, this is the number of bytes. For CLOB and NCLOB type LOBs, this is thenumber of UCS-2 code points. UCS-2 code points are equivalent to charactersfor all but supplemental characters.
- LOB.trim(new_size=0)
Trims the LOB to the new size.
- LOB.write(data,offset=1)
Writes the data to the LOB object at the given offset. The offset is inbytes for BLOB type LOBs and in UCS-2 code points for CLOB and NCLOB typeLOBs. UCS-2 code points are equivalent to characters for all butsupplemental characters. If supplemental characters are in the LOB, theoffset will have to be chosen carefully to avoid splitting a character.Note that if you want to make the LOB value smaller, you must use the
trim()
function.
12.2.LOB Attributes
- LOB.type
This read-only attribute returns the type of the LOB as one of thedatabase type constants.