函数名称:OCILob::truncate()
适用版本:PHP 5, PHP 7
函数描述:OCILob::truncate() 函数用于截断一个大型对象(LOB)的内容。
语法:bool OCILob::truncate ( int $length )
参数:
返回值:成功时返回 true,失败时返回 false。
示例:
<?php
// 创建一个新的连接
$conn = oci_connect('username', 'password', 'localhost/XE');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
// 准备 SQL 语句
$sql = "SELECT clob_column FROM my_table WHERE id = :id FOR UPDATE";
$stmt = oci_parse($conn, $sql);
if (!$stmt) {
$e = oci_error($conn);
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$id = 1;
oci_bind_by_name($stmt, ':id', $id);
// 执行查询
oci_execute($stmt);
// 获取 LOB 对象
$lob = oci_fetch_assoc($stmt)['CLOB_COLUMN'];
// 截断 LOB 内容为指定长度
$length = 100;
if ($lob->truncate($length)) {
echo "LOB truncated successfully.";
} else {
echo "Failed to truncate LOB.";
}
// 关闭连接
oci_free_statement($stmt);
oci_close($conn);
?>
注意事项: