连接VB脚本和SQL Plus,将值传递给查询

连接VB脚本和SQL Plus,将值传递给查询,sql,scripting,vbscript,sqlplus,Sql,Scripting,Vbscript,Sqlplus,从文本文件中读取后,我尝试使用存储在变量中的值连接到SQLplus,并尝试更新表,但出现以下错误:“Unterminated String constant” 下面是代码的样子,感谢Guido在步骤1中帮助我。 任何人都可以指出错误。If&Else部分中的一些错误,SQL查询或连接是错误的 dim fs, txt, line, yesno , cust_id set fs = CreateObject("Scripting.FileSystemObject") set txt = fs.Open

从文本文件中读取后,我尝试使用存储在变量中的值连接到SQLplus,并尝试更新表,但出现以下错误:“Unterminated String constant” 下面是代码的样子,感谢Guido在步骤1中帮助我。 任何人都可以指出错误。If&Else部分中的一些错误,SQL查询或连接是错误的

dim fs, txt, line, yesno , cust_id
set fs = CreateObject("Scripting.FileSystemObject")
set txt = fs.OpenTextFile("E:\batchfiletest\Eapp3\scotia1.txt", 1, false) 

' loop through all the lines
do while not txt.AtEndOfStream
    line = txt.readLine

' read the character and store it in a variable
    yesno = Mid(line, 127, 1)
    cust_id = Mid(line, 1,20)   

' execute the correct query
    if yesno = "Y" then

    set WshShell = CreateObject("WScript.Shell")
    set oEnv=WshShell.Environment("Process") 
    cmdString = "E:\oracle\product\10.2.0\db_1\BIN\sqlplusw.exe -S sysman/csaadmin@convcsd

    UPDATE csa_sli_all.T_CONV_quote set HOLD_CODE = 'CAQ' where quote_id =  cust_id ;
    commit;"

    Set oExec = WshShell.Exec(cmdString)

     ELSE  
    set WshShell = CreateObject("WScript.Shell")
    set oEnv=WshShell.Environment("Process") 
    cmdString = "E:\oracle\product\10.2.0\db_1\BIN\sqlplusw.exe -S sysman/csaadmin@convcsd

    UPDATE csa_sli_all.T_CONV_quote set HOLD_CODE = 'PVQ' where quote_id =  cust_id ;
    commit;"

    Set oExec = WshShell.Exec(cmdString)

    end if
loop
MsgBox "Press OK to close when done reading the output."

通常更快更安全的方法是

Const sConnectionStringOracle =  "Provider=OraOLEDB.Oracle;Data Source=xxxx.xxxxx;User id=xxx;password=xxx"
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open sConnectionStringOracle
sql = "UPDATE csa_sli_all.T_CONV_quote set HOLD_CODE = 'CAQ' where quote_id = " & cust_id
oConn.execute(sql)
'rest of the database transactions
oConn.close
Set oConn = nothing
您可以添加错误捕获、日志记录等。 只要确保在使用本软件的pc上安装了Oracle OleDb驱动程序即可。 如果您需要使用Sql*Plus,则将所有事务写入一个Sql文本文件,并仅运行一次。然后,您可以在出现错误时执行和调试Sql


Grtz

在没有Oracle OleDb驱动程序的情况下,是否有其他方法来获取或更新数据,在我们的办公系统中,驱动程序安装受到限制。我可以访问sqlplus以连接到数据库,并使用带有vba脚本的excel。如果安装了ODBC数据库驱动程序,则可以使用ODBC数据库驱动程序,连接字符串略有不同,ODBC比leDb尽管如此,如果不可能,请在startmenu中搜索odbc,尝试通过sql*Plus运行sql文件的解决方案,就像我在a&nswer中建议的那样。没有使用vba的经验,抱歉