---
title: "php oracle CLOB"
author: "jcyzone"
date: "2013-03-05T10:49:27Z"
tags: []
categories: ["编程语言"]
slug: "php-oracle-clob"
draft: false
lastmod: "2013-03-05T10:49:27Z"
id: 1819610
url: "https://jcyzone.iteye.com/blog/1819610"
---

1.php insert oracle 的CLOB字段

$sql = "INSERT INTO NC57.lsdcu\_callreport(pk\_cu\_callreport,pk\_cumandoc,evaluate,visittype,ansales,anpurchases,visitdate,creator,createtime,pk\_dept,visitpurpose,customadd,attcustomers,attoriginal,attrname) VALUES('".$pk\_cu\_callreport."','".$pk\_cumandoc."','".$evaluate."','".$visittype."','".$ansales."','".$anpurchases."','".$visitdate."','".$\_SESSION\['erp\_upk']."','".date('Y-m-d H:i:s')."','".$\_SESSION\['erp\_udpk']."','".$visitpurpose."','".$customadd."','".$attcustomers."','".$attoriginal."',EMPTY\_CLOB())       RETURNING          attrname INTO :mylob\_loc";  
 $test\_query = oci\_parse($conn, $sql);  
 $myLOB = oci\_new\_descriptor($conn, OCI\_D\_LOB);  
 oci\_bind\_by\_name($test\_query, ":mylob\_loc", $myLOB, -1, OCI\_B\_CLOB);  
 try {  
  oci\_execute($test\_query, OCI\_DEFAULT);  
 } catch (Exception $e) {  
  echo message\_and\_redirect('alert', '添加失败：'.$e-&gt;getMessage(), -1);  
  exit;  
 }  
 $myLOB-&gt;save($attrname);  
 oci\_commit($conn);  
 oci\_free\_statement($test\_query);  
 $myLOB-&gt;free();

2：php更新oracle CLOB字段

$attrname     = iconv('utf-8', 'gbk',request\_var('attrname', ''));  
 $up\_sql = "UPDATE NC57.lsdcu\_callreport SET attrname = EMPTY\_CLOB() WHERE pk\_cu\_callreport = '".$id."' RETURNING attrname INTO :mylob";  
 $stmt = OCIParse($conn, $up\_sql);  
    $mylob = OCINewDescriptor($conn,OCI\_D\_LOB);  
    OCIBindByName($stmt,':mylob',$mylob, -1, OCI\_B\_CLOB);  
    // Execute the statement using OCI\_DEFAULT (begin a transaction)  
    OCIExecute($stmt, OCI\_DEFAULT)  
    or die ("Unable to execute query\\n");  
    if ( !$mylob-&gt;save($attrname) ) {  
     OCIRollback($conn);  
     echo message\_and\_redirect('alert', '修改失败', '/erp/list.html');  
  exit;  
    }  
    OCICommit($conn);  
    $mylob-&gt;free();  
    OCIFreeStatement($stmt);  
 echo message\_and\_redirect('alert', '修改成功', '/erp/list.html');  
 exit;

[http://www.oracle.com/technetwork/articles/fuecks-lobs-095315.html](http://www.oracle.com/technetwork/articles/fuecks-lobs-095315.html)