php insert Oracle clob 字段处理问题
生活随笔
收集整理的這篇文章主要介紹了
php insert Oracle clob 字段处理问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
php insert Oracle clob 字段處理問題 如果接觸過mysql的話一定對mysql的text和blob不會陌生,在mysql中是直接操作text和blob的。但是在oracle中,它把lob做為一種特殊的字段,不能直接進行操作--比如不能直接插入到lob字段中,也不能用like查詢等等。?????
? 不能直接用INSERT語句向LOB字段中插入值。一般情況下,有如下的幾步: ? ?
? 1 ? 先分析一個INSERT語句,返回一個LOB的描述符 ? ?
? 2 ? 用OCI函數生成一個本地的LOB對象 ? ?
? 3 ? 將LOB對象綁定到LOB描述符上 ? ?
? 4 ? 執行INSERT語句 ? ?
? 5 ? 給LOB對象賦值 ? ?
? 6 ? 釋放LOB對象和SQL語句句柄?????
?/* ?
? //(tabel_name:article)DDL; ? //just ? for ? test; ? ?
? //create ? table ? article(id ? number(11),content ? clob); ? ?
? */ ?
? ?
? //----------This ? is ? insert ? test---------------------------------- ? ?
? $conn ? = ? @OCILogon("YourUsername","YourPassword","YourDatabase"); ?
? ?
? $stmt ? = ? @OCIParse($conn,"insert ? into ? article ? values(1,EMPTY_CLOB()) ? RETURNING ? content ? INTO:CONTENT"); ? ?
? $clob ? = ? @OCINewDescriptor($conn,OCI_D_LOB);???
????OCIBindByName($stmt,':CONTENT',&$clob,-1,OCI_B_CLOB);
if(!OCIExecute($stmt, OCI_DEFAULT)) {print_r(OCIError($stmt));}
if($clob->save($CONT))
{
OCICommit($conn);
}
else
{
print_r(OCIError($stmt));
}?????
? //---------------Insert ? end----------------------------------------- ?
? ?
? ?
? //---------------Select ? start--------------------------------------- ?
? $sql ? = ? "select ? content ? from ? article ? order ? by ? id ? desc"; ?
? $stmt ? = ? @OCIParse($conn,$sql); ?
? @OCIExecute($stmt,OCI_DEFAULT); ?
? @OCIFetchInto($stmt,&$rows,OCI_RETURN_LOBS); ?
? echo ? "<br>Content ? is:\"".$rows[0]."\""; ?
? ?
? //---------------Select ? end-----------------------------------------
注意:測試時一定注意Oracle的保留關鍵字,經常使用OCIError來差錯。 posted on 2008-06-23 16:54 jiafan 閱讀(...) 評論(...) 編輯 收藏
? 不能直接用INSERT語句向LOB字段中插入值。一般情況下,有如下的幾步: ? ?
? 1 ? 先分析一個INSERT語句,返回一個LOB的描述符 ? ?
? 2 ? 用OCI函數生成一個本地的LOB對象 ? ?
? 3 ? 將LOB對象綁定到LOB描述符上 ? ?
? 4 ? 執行INSERT語句 ? ?
? 5 ? 給LOB對象賦值 ? ?
? 6 ? 釋放LOB對象和SQL語句句柄?????
?/* ?
? //(tabel_name:article)DDL; ? //just ? for ? test; ? ?
? //create ? table ? article(id ? number(11),content ? clob); ? ?
? */ ?
? ?
? //----------This ? is ? insert ? test---------------------------------- ? ?
? $conn ? = ? @OCILogon("YourUsername","YourPassword","YourDatabase"); ?
? ?
? $stmt ? = ? @OCIParse($conn,"insert ? into ? article ? values(1,EMPTY_CLOB()) ? RETURNING ? content ? INTO:CONTENT"); ? ?
? $clob ? = ? @OCINewDescriptor($conn,OCI_D_LOB);???
????OCIBindByName($stmt,':CONTENT',&$clob,-1,OCI_B_CLOB);
if(!OCIExecute($stmt, OCI_DEFAULT)) {print_r(OCIError($stmt));}
if($clob->save($CONT))
{
OCICommit($conn);
}
else
{
print_r(OCIError($stmt));
}?????
? //---------------Insert ? end----------------------------------------- ?
? ?
? ?
? //---------------Select ? start--------------------------------------- ?
? $sql ? = ? "select ? content ? from ? article ? order ? by ? id ? desc"; ?
? $stmt ? = ? @OCIParse($conn,$sql); ?
? @OCIExecute($stmt,OCI_DEFAULT); ?
? @OCIFetchInto($stmt,&$rows,OCI_RETURN_LOBS); ?
? echo ? "<br>Content ? is:\"".$rows[0]."\""; ?
? ?
? //---------------Select ? end-----------------------------------------
注意:測試時一定注意Oracle的保留關鍵字,經常使用OCIError來差錯。 posted on 2008-06-23 16:54 jiafan 閱讀(...) 評論(...) 編輯 收藏
轉載于:https://www.cnblogs.com/jiafan/archive/2008/06/23/1228300.html
總結
以上是生活随笔為你收集整理的php insert Oracle clob 字段处理问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 专家系列教程:遭受***后的证据有哪些?
- 下一篇: 我在51CTO的第一篇博文!