VBS连接远程Oracle

原文链接:http://hi.baidu.com/coo_boi/item/5a2e1860ded285136995e6a7

连接方式还是用的ADO,驱动是MSDAORA。

使用oracle前,oracle client必须要装的,而且tnsnames.ora也要配置的。

'__code by coo_boi
'__vbs & oracle
Set cnn=CreateObject("adodb.connection")
Set rds=CreateObject("adodb.recordset")
Set cmd=CreateObject("adodb.command") cnnstr="Provider=MSDAORA.1;User ID=eastcom;" & _
"Password=EastcoM!$;" & _
"Data Source=MART11G;" & _
"Persist Security info=False"
cnn.Open cnnstr
'===================================================
'regular select
Set rds=cnn.Execute("select * from v$version")
Do Until rds.EOF Or rds.EOF
version= version & rds.Fields() & vbLf
rds.MoveNext
Loop
MsgBox version,,"select * from v$version"
'===================================================
'insert/delete/update
'ra: RecordAffected
' execute DML without needing to commit,
' and it only can execute one dml sentence every execution period.
cnn.Execute "insert into temp_column values('4567')", ra
MsgBox ra
cnn.Execute "delete temp_column where rt='1234'", ra
MsgBox ra
cnn.Execute "update temp_column set rt='xxx' where rt='4567'", ra
MsgBox ra
'===================================================
'execute procedure
cmd.ActiveConnection=cnn
cmd.CommandType=
cmd.CommandText="proc_getversion"
Set para1=cmd.CreateParameter("v1",,,,"hello,this is coo_boi")
Set para2=cmd.CreateParameter("v2",,,,"")
cmd.Parameters.Append para1
cmd.Parameters.Append para2
cmd.Execute
MsgBox cmd.Parameters().Value,,"execute procedure" cnn.Close

范例中的存储过程:

create or replace procedure
proc_getversion(v1 in varchar,v2 out varchar)
as
begin
v2 := v1;
for t in (select * from v$version)
loop
v2 := v2 || chr(13) || t.banner;
end loop;
end;

返回结果:

VBS连接远程Oracle

上一篇:javaweb笔记二


下一篇:POJ 2392 Space Elevator 背包题解