标签:
CREATE SEQUENCE mylobs_id_seq
NOMINVALUE
NOMAXVALUE
NOCYCLE
CACHE 20
NOORDER
INCREMENT BY 1;
CREATE TABLE mylobs (
id NUMBER PRIMARY KEY,
mylob CLOB
)
插入
<?php header("content-type:text/html;charset=utf-8"); error_reporting(E_ALL); set_time_limit(0); echo "<pre>"; $conn=oci_connect(‘demo‘,‘demo‘,‘localhost/xe‘,‘utf8‘); $sql = "INSERT INTO mylobs ( id, mylob ) VALUES ( mylobs_id_seq.NEXTVAL, EMPTY_CLOB() ) RETURNING mylob INTO :mylob_loc"; $stmt = oci_parse($conn, $sql); $myLOB = oci_new_descriptor($conn, OCI_D_LOB); oci_bind_by_name($stmt, ":mylob_loc", $myLOB, -1, OCI_B_CLOB); oci_execute($stmt, OCI_DEFAULT) or die ("Unable to execute query\n"); $content=str_repeat(‘你‘,80000); if ( !$myLOB->save($content) ) { oci_rollback($conn); } else { oci_commit($conn); } oci_free_statement($stmt); $myLOB->free(); oci_close($conn); |
查询
<?php header("content-type:text/html;charset=utf-8"); error_reporting(E_ALL); set_time_limit(0); echo "<pre>"; $conn=oci_connect(‘demo‘,‘demo‘,‘localhost/xe‘,‘utf8‘); $sql = "SELECT * FROM mylobs ORDER BY id"; $stmt = oci_parse($conn, $sql); oci_execute($stmt) or die ("Unable to execute query\n"); while ( $row = oci_fetch_assoc($stmt) ) { echo "ID: {$row[‘ID‘]}, "; echo $row[‘MYLOB‘]->load()."\n"; } oci_free_statement($stmt); oci_close($conn); |
修改
<?php header("content-type:text/html;charset=utf-8"); error_reporting(E_ALL); set_time_limit(0); echo "<pre>"; $conn=oci_connect(‘demo‘,‘demo‘,‘localhost/xe‘,‘utf8‘); $sql = "SELECT mylob FROM mylobs WHERE id = 1 FOR UPDATE"; $stmt = oci_parse($conn, $sql); oci_execute($stmt, OCI_DEFAULT) or die ("Unable to execute query\n"); if ( FALSE === ($row = oci_fetch_assoc($stmt) ) ) { oci_rollback($conn); die ("Unable to fetch row\n"); } if ( !$row[‘MYLOB‘]->truncate() ) { oci_rollback($conn); die ("Failed to truncate LOB\n"); } if ( !$row[‘MYLOB‘]->save(‘UPDATE: ‘.date(‘H:i:s‘,time()) ) ) { oci_rollback($conn); } else { oci_commit($conn); } oci_free_statement($stmt); $row[‘MYLOB‘]->free(); oci_close($conn); |
标签:
原文地址:http://www.cnblogs.com/songzhenghe/p/4582318.html