如何使用 VBScript 执行 Oracle SQL 语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1103804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Execute an Oracle SQL Statements with VBScript
提问by Arno Conradie
I am trying to execute an Oracle SQL statement or Oracle Functions through Microsoft VBScript and the loop throught the result set or display the value returned by the function
我正在尝试通过 Microsoft VBScript 和循环执行 Oracle SQL 语句或 Oracle 函数,通过结果集或显示函数返回的值
So far I have managed to connect to Oracle via SQLPlus*, but now I am stuck. Can anybody help?
到目前为止,我已经设法通过 SQLPlus* 连接到 Oracle,但现在我被卡住了。有人可以帮忙吗?
Dim output
Dim WshShell, oExec, input
set WshShell = CreateObject("WScript.Shell")
set oEnv=WshShell.Environment("Process")
cmdString = "C:\Oracleg\product.1.0\ruby\BIN\sqlplus.exe -S stradmin/stradmin@ruby select * from dual"
Set oExec = WshShell.Exec(cmdString)
WScript.Echo "Status" & oExec.Status
Do While oExec.Status = 0
WScript.Sleep 2
Loop
input = ""
Do While Not oExec.StdOut.AtEndOfStream
input = input & oExec.StdOut.Read(1)
Loop
wscript.echo input
回答by Tester101
Try this it should add each field in the recordset to the input string. If you only want a specific value from each record you can do this
试试这个它应该将记录集中的每个字段添加到输入字符串中。如果您只想要每个记录的特定值,您可以这样做
input = input & rs.Fields.Item("FIeld_Name")
Instead of looping though each field.
而不是循环每个字段。
connectionString = "DRIVER={Microsoft ODBC for Oracle};SERVER=oracle_server;User Id=user;Password=password;"
Set connection = CreateObject("ADODB.Connection")
connection.Open connectionString
Set rs = connection.Execute("select * from dual")
input = ""
Do Until rs.EOF
for i = 0 To rs.Fields.Count - 1
input = input & rs.Fields.Item(i) & "|"
Next
input = input & VBNewLine
rs.MoveNext
Loop
MsgBox input
Set connection = Nothing
Set rs = Nothing