2009-07-09 74 views
1

我試圖執行一個Oracle SQL語句或通過Microsoft VBScript中的Oracle功能和循環throught結果集或顯示如何使用VBScript

到目前爲止,我有函數返回值來執行一個Oracle SQL語句設法通過SQLPlus *連接到Oracle,但現在我卡住了。任何人都可以幫忙嗎?


Dim output 

Dim WshShell, oExec, input 

set WshShell = CreateObject("WScript.Shell") 

set oEnv=WshShell.Environment("Process") 

cmdString = "C:\Oracle\11g\product\11.1.0\ruby\BIN\sqlplus.exe -S stradmin/[email protected] 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 

回答

3

試試這個,應該將記錄集中的每個字段添加到輸入字符串。如果你只想從每條記錄中得到一個特定的值,你可以這樣做:

input = input & rs.Fields.Item("FIeld_Name") 

而不是循環每個字段。

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