If you have been in contact with MySQL, you must be familiar with MySQL text and Blob. in MySQL, you can directly operate on text and blob. However, in Oracle, it regards lob as a special field and cannot perform operations directly-for example, it cannot be directly inserted into the lob field or like query.
Values cannot be directly inserted into the lob field using the insert statement. Generally, there are the following steps:
1. analyze an insert statement and return a lob descriptor.
2 Use OCI Functions Generate A local lob object
3. Bind the lob object to the lob descriptor.
4. Execute the insert statement
5. assign a value to the lob object
6. Release lob objects and SQL statement handles
/*
// (Tabel_name: article) DDL; // just for test;
// Create table article (ID number (11), content clob );
*/
// ---------- This is insert test ----------------------------------
$ Conn = @ ocilogon ("yourusername", "yourpassword", "yourdatabase ");
$ Stmt = @ ociparse ($ Conn, "insert into article values (1, empty_clob () returning content into: content ");
$ Clob = @ ocinewdescriptor ($ Conn, oci_d_lob );
Ocibindbyname ($ stmt, ': content', & $ clob,-1, oci_ B _clob );
If (! Ociexecute ($ stmt, oci_default) {print_r (ocierror ($ stmt ));}
If ($ clob-> Save ($ cont ))
{
Ocicommit ($ conn );
}
Else
{
Print_r (ocierror ($ stmt ));
}
// --------------- Insert end -----------------------------------------
// --------------- Select Start ---------------------------------------
$ SQL = "select content from article order by ID DESC ";
$ Stmt = @ ociparse ($ Conn, $ SQL );
@ Ociexecute ($ stmt, oci_default );
@ Ocifetchinto ($ stmt, & $ rows, oci_return_lobs );
Echo "<br> content is: \" ". $ rows [0]." \ "";
// --------------- Select end -----------------------------------------
Note: you must pay attention to the reserved keywords of Oracle during testing. ocierror is often used for errors.