我使用在ASP程序中使用ADO连接ORA数据库,代码如下:
表aaa,字段id(varchar2),字段value(clob)
<%
c="大于4000的字符串"
set conn = server.createObject("adodb.connection")
conn.Open "Provider=MSDAORA.1;Persist Security Info=True;User ID=用户;Password=密码;Data Source=名称"
conn.execute("insert into aaa (id,value) values('1',empty_clob())")
conn.execute("update aaa set value='"&c&"' where id='1'")
%>
当c小于4000可正常执行,大于4000就会报错“错误原因:ORA-01704: 文字字符串过长”,请问该怎样才能把大于4000的字符保存与clob中?并取出显示!

解决方案 »

  1.   

    Reference: ASP: Articles: ADO, Oracle and (Text in) BLOBs
    Questions to Karen WallaceThis tutorial covers loading a text into a BLOB using Oracle's OLEDB Provider. Why on earth, you make ask, would you want to do that when you could just put the text in a CLOB? Maybe you have data that could be text or binary and should all go into the same table because it's related and has the same properties. Real life example: You allow users to store HTML and images in the database for simple webpages. Yes, you could just store the images on disk, but you have a web farm and you don't want to deal with deployment and undeployment to and from multiple servers, and the traffic on these pages will be light. In other words, you're lazy and looking to program something new.If you've read the related tutorial on storing binary data in BLOBs, you'll find this very similar.I. Load the Text Data into the Database
    Get an updatable recordset and shove the text into the recordset. As working with LOBs of any sort involves transactions whether you want them or not, it's advisable to wrap your databasing in a transaction. Always initialize your BLOB field with empty_blob().<%
    dim conn, rsset conn = server.createObject("adodb.connection")
    conn.open "Provider=OraOLEDB.Oracle;Data Source=oracle.mydomain.com;User ID=scott;PASSWORD=tiger"set rs = server.createObject("adodb.recordset")conn.beginTrans'Use this for an update
    conn.execute "UPDATE blobtable SET blobcolumn = empty_blob() WHERE id = 7"
    rs.open "SELECT blobcolumn FROM blobtable WHERE id = 7", conn, adOpenStatic, adLockOptimistic'Or this for an insert
    conn.execute "INSERT INTO blobtable (id, blobcolumn) VALUES (blobtable_seq.nextVal, empty_blob())"
    rs.open "SELECT blobcolumn FROM blobtable WHERE id = blobtable_seq.currVal", conn, adOpenStatic, adLockOptimisticrs.fields("blobcolumn").appendChunk(lotsOfText)
    rs.update
    rs.closeconn.commitTrans
    %>II. Retrieve the Text Data from the Database
    You can write to the browser or to disk. Streams default to UTF-8, which might not match your database's character set, you must convert it. Plus, the ASP engine doesn't like to read unicode.<%
    dim conn, rsset conn = server.createObject("adodb.connection")
    conn.open "Provider=OraOLEDB.Oracle;Data Source=oracle.mydomain.com;User ID=scott;PASSWORD=tiger"set rs = conn.execute("SELECT blobcolumn FROM blobtable WHERE id = 7")'Write it to the browser
    response.write rs.fields("blobcolumn").value'Write it to disk
    dim stream
    set stream = server.createObject("adodb.stream")
    stream.type = adTypeText
    stream.charset = "iso-8859-1"
    stream.open
    stream.writeText(rs.fields("blobcolumn").value)
    stream.saveToFile folderAndFileName, adSaveCreateOverWrite
    stream.close
    %>Good Luck
      

  2.   

    这篇文章我看过,试了一下提示错误说缺少OraOLEDB驱动
    我的环境是win2k adv server + Oracle服务器版完全安装
    我奇怪怎么会说OraOLEDB驱动没有?
    另外我看资料说appendChunk这种方法不是很稳定,文本过大或进程过多容易造成IIS死掉,不知道是不是这样?
      

  3.   

    如果你安装了Oracle客户端或者Oracle服务端的话。应该有这个驱动的呀。不行的话你可以选用ODBC,或者额外安装OLEDB驱动。appendchunk没什么大问题。
    我一般存几兆大小的文件,没出过错。
    不过建议是用buffer写入。
      

  4.   

    你可能没有完全安装数据库:
    你使用ADO创建连接看下是否有这个驱动,如果没有重新安装数据库,试
      

  5.   

    使用oralce objects for ole(oo4o)吧,是oracle自己提供的,
     缺省安装后就有这个组件,很好用.
      

  6.   

    建议你连接ORACLE的话,用下面的代码,比ADO快并且好用
    set orasession=createobject("OracleInprocServer.XOraSession") 
    set oradatabase=orasession.dbopendatabase("ora8","test_word/test",0)
      

  7.   

    我用oo4o写的:
    <%
    c="大于4000的字符串"
    set orasession=createobject("OracleInprocServer.XOraSession") 
    set oradatabase=orasession.dbopendatabase("ora8","test_word/test",0)
    Set OraDynaset=OraDatabase.DbCreateDynaset("select * from aaa",0)
    OraDynaset.addnew
    OraDynaset.Fields("id").value = "1"
    OraDynaset.Fields("value").appendChunk(c)
    OraDynaset.Update
    Set OraDynaset=OraDatabase.DbCreateDynaset("select dbms_lob.substr(value) from aaa where id=1",0)
    response.write OraDynaset("dbms_lob.substr(value)")
    %>
    程序没有报错,但是好像value字段内没有存入值!response.write打出来是空值!
      

  8.   

    你的代码还是有问题的,因为你没有用empty_clob()方法初始化clob字段.
     可以参考一下 $ORACLE_HOME\oo4o\vb\sampleslob目录下的程序.
      

  9.   

    上面的路径写错了应该是: $ORACLE_HOME\oo4o\vb\samples\lob