在我开发BS结构程序中,由于经常需要在ORACLE中处理一些容量较大的文本数据,所以经过反复测试终于
一、运行环境:
1、Microsoft Windows 2000 Server + IIS 5.0
2、Oracle8i中文标准版
二、建立数据表:
CREATE TABLE SYSTEM.TEST(
BLOB LONG,
ID NUMBER)
/
1、数据存入程序:test.asp
<%
'表单提交处理部分
'--------------------------------------------------
function tansstr(sstr)
sstr=replace(sstr," "," ")
sstr=replace(sstr,chr(13) & chr(10),"<br>")
tansstr=sstr
end function
a=lenb(request("text"))
b=len(request("text"))
c=tansstr(request("text"))
Set OraSession=CreateObject("OracleInProcServer.XOraSession")
Set OraDatabase=OraSession.DbOpenDatabase("autop","system/manager",0)
Set rs=OraDatabase.CreateDynaset("select * from test order by id desc",0)
if rs.eof then
id=1
else
id=rs("id")+1
end if
'--------------------------------------------------------
rs.DbAddNew
rs.Fields("blob").DbAppendChunk(c)
rs("id")=id
rs.DbUpdate
'显示结果部分
'---------------------------------------------------------
Response.write "数据已经存入数据库中。<br>"
Response.write "总计占用字符数: <font color=blue>" & formatnumber(b,2,-2,-2,-1) & "</font
Response.write "总计占用字节数: <font color=blue>" & formatnumber(a,2,-2,-2,-1) & "</font
Response.write "<a href='view.asp'>请调阅……</a>"
rs.close
set rs=nothing
Set OraSession=nothing
Response.end
End If
%>
<html>
<body>
<form method="POST" action="test.asp">
<p><font color="#FF0000"><b>Oracle大字段在ASP中存取问题的解决:</b></font></p>
<p><textarea rows="13" name="text" cols="104"></textarea></p>
<p><input type="submit" value="存入" name="B1"></p>
<input type="hidden" name="ok" value="1">
</form>
</body>
</html>
2、数据调出程序:view.asp
Set OraSession=CreateObject("OracleInProcServer.XOraSession")
Set OraDatabase=OraSession.DbOpenDatabase("autop","system/manager",0)
Set Rs=OraDatabase.DbCreateDynaset("select * from test order by id desc",4)
Size=65280
I=0
'以Rs记录集的Fields对象的DbGetChunk方法在循环中读出数据
Text=Rs.Fields("Blob").DbGetChunk(I*Size,Size)
Text_Size=Lenb(Text)
Loop until Text_Size<Size
Set OraSession=nothing