2

我有一个以下格式的txt文件

11SNMMMMTESTCASEJBS1961123123232YExist 

从这个文件中,我必须检查第 33 列的值,即 Y 或 N。如果是 N,我必须转到数据库并使用以下查询

Update table XYZ set Status = Not Exist where cust_id = ** ( taken from record)

如果是 Y

Update table XYZ set Status = Exist where cust_id = ** ( taken from record)

从文本文件读取后,我尝试使用存储在变量中的值连接到 SQLplus,并尝试更新表,但出现以下错误:“未终止的字符串常量这是代码的样子,感谢 Guido 的帮助我在第 1 步上。任何人都可以指出错误。If & Else Part 中的一些错误,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."
4

1 回答 1

4

看看 vbscript字符串函数。专门寻找Mid功能。

然后,您应该能够读取特定的字符位置,并执行正确的查询。

从文本文件中读取行、从行中存储字符并稍后使用它的示例:

dim fs, txt, line, yesno

' create a file system object and open the text file
set fs = CreateObject("Scripting.FileSystemObject")
set txt = fs.OpenTextFile("C:\Users\dgaurav\Deskto‌​p\CSA -3\scotia.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, 33, 1)

    ' execute the correct query
    if yesno = "Y" then
        WScript.Echo "Yes"
    else
        WScript.Echo "No"
    end if
loop
于 2012-04-10T09:10:07.237 回答