在ASP中,如何存储大于4000字节的数据类型开ORACLE数据库中!库中的字段类型我用的是CLOB大字符类型!但是提示说字符串字节过长!

解决方案 »

  1.   

    用ADO连Oracle,你不能直接向CLOB里面写得,否则会被当作varchar2处理。先要 启动事务然后在insert 或者 update 中 fieldCLOB = empty_clob()接着通过buffer 将字节流写入。最后 提交事务
      

  2.   

    你好!在ASP中如何启动事务,代码是:举个例子!
    你比如:有一个变量是传递大字符的,如何用INSERT INTO 到一个表中
    比如:INSERT INTO ASDF1(A,B) VALUES('"&A&"',)省略号中怎么写??
    通过BUFFER将字节流写入代码是如何写的??
    请多多指教!!!我给分的!谢谢!
      

  3.   

    connection.begintrans()
    connection.committrans()
    connection.rollbacktrans()可能有点不一样,应该差不多。sql = "insert into t (a,b),values(1,empty_clob())"你应该是用"ADODB.Recordset"的吧。那个对象应该有写入字节流的方法。(很久没写ASP了,记不清了)
    你不用Buffer,直接一下子写进去是可以的,
    不过太大的文件(几M),一下写不太好(但是我是过1、2M直接写入是可以的)。
    习惯上是一段一段写比较好。如果你的文件不是很大,直接写好了。
      

  4.   

    对了,
    insert以后,还要将刚才那条记录Select出来。通过记录集再将内容写入到这个字段。最后提交事务。
      

  5.   

    sql = "insert into t (a,b),values(1,empty_clob())"
    这一句代码中没有传递大字符的变量,也可以吗?
    我用的是ADODB。RECORDSET
    文件没有那么大,能存上个几万中文就可以了!
    我用了你说的方法,但是好像存不上的!
    多谢你了!sql = "insert into t (a,b),values(1,empty_clob())"就这样写吗?
      

  6.   

    对不起啊。前面忘了告诉你,empty_clob() 是先插入一个CLOB的指针,要求Oracle分配CLOB的数据区。然后把该记录再选取出来。
    用字节流写入就会写到分配好的数据区了。insert和select 出来修改必须在同一事务中完成。
      

  7.   

    for i=1 to intfieldcount
    strdata=strdata & request.Form("hdnbigfield" & i)
    next 
    s="insert into ASDF(a,b) VALUES('"&a&"',empty_clob())"
    cn.execute(s)
    还要添加什么代码?兄弟,请你多教一下!
      

  8.   

    上面的兄弟,救救我,能不能把下的代码具体的举个例子说明一下!
    很关键的!谢谢!
    在ASP中怎么选记录,选完之后怎么通过记录集、数据流再写入分配好的CLOB数据区呢!
      

  9.   

    rs.open("select b from asdf where a ='a'")rs("b").AppendChunk strdatars.update()你如果你是读取文件,可以定义一个4096的char数组,
    然后循环执行 rs("b").AppendChunk bufferappendchunk 的使用方法参见http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdamth01_3.asp
    Good luck
      

  10.   


    最重要的是执行insert和后来的update必须在一个事务里。cn.begintrans
      insert .....  select ....
      rs.updatecn.committrans发生错误要执行cn.rollbacktrans
      

  11.   

    for i=1 to intfieldcount 
    strdata=strdata & request.Form("hdnbigfield" & i)
    next 
    a=request.form("a")
    Set rs=Server.CreateObject("ADODB.RecordSet")
    cn.begintrans
    s="insert into ASDF(a,b) VALUES('"&a&"',empty_clob())"
    cn.execute(s)
    rs.open ("select b from asdf where a ='"&a&"' for update"),cn,3,2
    rs("b").AppendChunk strdata
    rs.update()
    cn.committrans
    为什么数据会丢失,例如:strdata 变量为1000个字节,可是存入数据库时只有650个字节!
      

  12.   

    这样啊。挺奇怪的。
    我倒是没有用ASP写过Oracle的大文本。你是用GetChunk获取写入的数据么?还有就是试试看不用AppendChunk。直接用rs("b")=strdata。我再帮你试试看吧。给分到帖子的管理里面就可以了。
      

  13.   

    帮你找了个帮助。BLOB和CLOB差不多啦。
    你再试试看吧。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
    %>
      

  14.   

    http://www.pep.com.cn/200212/ca3007.htm
    http://www.fawcette.com/china/print.aspx?TotalPage=6&ID=76