Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Newbie question regarding LOB
First you do a "select for update" to get the lob locator and lock the row.
Then you open the lob using OCILobOpen(), write into the lob using
OCILobWrite(), and then close the lob using OCILobClose(). Here's some
sample code:
void writeDataToLob(envhp, errhp, svchp, stmthp)
OCIEnv *envhp; OCIError *errhp; OCISvcCtx *svchp; OCIStmt *stmthp;
(void) OCIDescriptorAlloc((dvoid *) envhp, (dvoid **) &lob_ptr,
(ub4)OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0);
text *sqlstmt =
(text *) "SELECT lob_column FROM mytable \
WHERE id = 1 FOR UPDATE";OCIDefine *defnp1;
(ub4)strlen((char *)sqlstmt),
(ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT));
checkerr (errhp, OCIDefineByPos(stmthp, &defnp1, errhp, (ub4) 1,
(dvoid *) &lob_ptr, (sb4)0,
(ub2) SQLT_CLOB,(dvoid *) 0,
(ub2 *) 0, (ub2 *) 0, (ub4) OCI_DEFAULT));
/* Execute the select and fetch one row */
checkerr(errhp, OCIStmtExecute(svchp, stmthp, errhp, (ub4) 1, (ub4) 0,
(CONST OCISnapshot*) 0, (OCISnapshot*) 0, (ub4) OCI_DEFAULT));
checkerr (errhp, (OCILobOpen(svchp, errhp, lob_ptr, OCI_LOB_READWRITE)));
checkerr (errhp, OCILobWrite (svchp, errhp, lob_ptr, &amt,
(ub4) 1, buff, MAXSIZE,
OCI_ONE_PIECE, (dvoid *)0,
(sb4 (*)(dvoid*,dvoid*,ub4*,ub1 *))0,
0, SQLCS_IMPLICIT));
checkerr (errhp, OCILobClose(svchp, errhp, Lob_loc));
(void) OCIDescriptorFree((dvoid *) lob_ptr, (ub4) OCI_DTYPE_LOB);
return;
}
For more details, see
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96591/adl10pst.htm#1759678
HTH,
Dave
"Shankar" <shanky191_at_rediffmail.com> wrote in message news:24707dc9.0311101903.3ded3065_at_posting.google.com...
> I intend to write a BLOB to database by binding a variable of type > OCILobLocator through OCIBindByName and then OCIExecuteStmt....I get > this data from another module as a character array. How do i copy the > contents of the array into my OCILobLocator? > > char buff[MAXSIZE]; ---> contains the data i wish to write (MAXSIZE is > HUGE!) > OCILobLocator *lob_ptr; > > Now to copy buff to lob_ptr????Received on Tue Nov 11 2003 - 03:48:32 CST