2013-04-17 60 views
0

昨天我問了一個這樣的問題,但我還沒有得到任何答案。如何在PHP中處理Oracle CLOB?

點:我怎樣才能獲得CLOB參考,如在INSERT INTO或UPDATE語句:

$sql = "INSERT INTO table (data) VALUES (EMPTY_CLOB()) RETURNING data INTO :data"; 
$statement = oci_parse($conn, $sql); 
$descriptor = oci_new_descriptor($conn, OCI_DTYPE_LOB); 
oci_bind_by_name($statement, ':data', $descriptor, -1, OCI_B_CLOB); 
oci_execute($statement); 
$descriptor->save('5000 chars'); 
oci_free_descriptor($descriptor); 

所以,我想調用CLOB保存方法,無需插入和更新語句。 所以我試過了:

$sql = "SELECT data FROM table WHERE id = " . $fooid; 
$statement = oci_parse($conn, $sql); 
oci_execute($statement); 
$row = oci_fetch_assoc($statement); 
$row['DATA']->save('5000 chars'); 

如何?

Thx。

回答

1
$sql = "INSERT INTO table t (t.data) VALUES (EMPTY_CLOB()) RETURNING t.data.clob INTO :data"; 
$statement = oci_parse($conn, $sql); 
$descriptor = oci_new_descriptor($conn, OCI_DTYPE_LOB); 
oci_bind_by_name($statement, ':data', $descriptor, -1, OCI_B_CLOB); 
oci_execute($statement, 0); //no commit!!! 
$descriptor->save('5000 chars'); 
oci_commit($conn); 
oci_free_descriptor($descriptor);