createLob method
Create a temporary Large Object (LOB) for storing large data.
Creates a temporary LOB in the database that can be used to store and manipulate large text or binary data. Similar to python-oracledb's createlob().
Parameters:
lobType: Type of LOB to create:LobType.clob- Character LOB (for text data)LobType.blob- Binary LOB (for binary data)LobType.nclob- National Character LOB (for Unicode text)
Returns: An OracleLob object for reading/writing large data.
Example - Creating and Writing CLOB:
final clob = await connection.createLob(LobType.clob);
try {
await clob.write('This is a large text document...');
// Insert the LOB into a table
await connection.execute(
'INSERT INTO documents (id, content) VALUES (:1, :2)',
params: [docId, clob],
);
await connection.commit();
} finally {
clob.dispose();
}
Example - Creating and Writing BLOB:
final blob = await connection.createLob(LobType.blob);
try {
// Write binary data (e.g., image file)
final imageBytes = await File('photo.jpg').readAsBytes();
await blob.write(imageBytes);
await connection.execute(
'UPDATE employees SET photo = :1 WHERE id = :2',
params: [blob, employeeId],
);
await connection.commit();
} finally {
blob.dispose();
}
Important:
- Always call
dispose()on LOBs when done to free resources - Temporary LOBs exist only for the session duration
- Call commit to persist LOB data in the database
See also:
- OracleLob for LOB operations
- OracleLob.read to read LOB data
- OracleLob.write to write LOB data
Implementation
Future<OracleLob> createLob(LobType lobType) async {
_ensureConnected();
return OracleLob.createTemp(
dpiOracle: _dpiOracle,
connection: _connectionPtr.value,
context: _context,
lobType: lobType,
);
}