如何在PHP中处理Oracle CLOB?

时间:2013-04-17 11:27:05

标签: php oracle save clob

我昨天问过这样的问题,但我还没有得到任何答案。

关键点:如何获取CLOB引用,例如插入或更新语句:

$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);

所以,我想在没有insert和update语句的情况下调用clob save方法。 所以我试过了:

$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 个答案:

答案 0 :(得分: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);