vbs脚本操作Oracle

无论是SQL Server 还是Oracle等,经常面临重复性操作SQL语句相同而关键参数不同的数据库操作,如果直接在数据库开发工具里很难快速完成,而是用脚本则可以快速完成这项工作.

范例:

 

  
  
  
  
  1. Const ForReading = 1, ForWriting = 2  
  2.  
  3.  
  4. Dim oFso,Path,File,nowvar  
  5.  
  6. Dim adoConnection,strConnect,Rs,StrFilter  
  7. Set oFso = CreateObject("Scripting.FileSystemObject")  
  8.  
  9. Set adoConnection = CreateObject("ADODB.Connection")  
  10.  
  11. '配置数据库连接源  
  12. strConnect = "Provider=MSDAORA;Data Source=ORCL;User ID=bcacc;Password=4;" 
  13.  
  14. adoConnection.Open strConnect  
  15.  
  16.  
  17. 'NoRec_Operating   
  18.  
  19. Dim constSql   
  20. constSql = "insert into ivr_channel_para t (t.ivr_channel_id,t.para_name,t.para_value) values ("   
  21.  
  22. For  i = 5 To 32   
  23.     WScript.Echo "正在设置:" & i &"通道反极信号..." 
  24.     StrSql = constSql & i &",'BasicPara.skipLineCheck','false') " 
  25.     adoConnection.Execute(StrSql)  
  26.     StrSql = constSql & i &",'ExtInfo.poleReverse','true') " 
  27.     adoConnection.Execute(StrSql)  
  28.     StrSql = constSql & i &",'ExtInfo.sendCallerNumber','true') " 
  29.     adoConnection.Execute(StrSql)         
  30. Next   
  31.  
  32.  
  33. '--------------------------------------------------------------------------------' 
  34. Function Find_PhoneNumber_Rec(Path,File) 'Path:目标文件夹,File:电话号码源文件  
  35.  
  36.     Dim DestFloder,FilePath,Start_Time,End_Time,DestFile  
  37.       
  38.     Dim StrSql,PhoneNumber  
  39.       
  40.       
  41.     DestFloder = Path  
  42.       
  43.     FilePath = File  
  44.       
  45.     '打开电话号码源文件  
  46.     Set objFile = oFso.OpenTextFile(FilePath,ForReading)  
  47.       
  48.           
  49.     '查询的起止日期  
  50.     Start_Time = "2010-" & Right(Path,5)  
  51.       
  52.     End_Time = Start_Time  
  53.       
  54.     '-------------------------------------------------------------------------------------  
  55.     '查询目标  
  56.     StrSql = "select t.fcalled ,t.rec_filename from tf_cdr t " 
  57.       
  58.     '时间过滤  
  59.     StrFilter = "where t.call_start_time between to_date('" & Start_Time &" 00:00:00','yyyy-MM-dd HH24:mi:ss')" 
  60.  
  61.     StrFilter = StrFilter & " and to_date('" & End_Time & " 23:59:59','yyyy-MM-dd HH24:mi:ss')" 
  62.  
  63.     StrFilter = StrFilter & " and t.rec_filename is not null " 
  64.     '--------------------------------------------------------------------------------------  
  65.       
  66.     StrSql = StrSql & StrFilter   
  67.       
  68.     While Not objFile.AtEndOfStream  
  69.       
  70.         PhoneNumber = objFile.ReadLine  '录音文件的电话号码  
  71.  
  72.         Set Rs  = adoConnection.execute(StrSql & " and t.fcalled = '" & PhoneNumber &"'" )  
  73.           
  74.         If  Rs.EOF Then   
  75.           
  76.             WScript.Echo PhoneNumber,"没有录音"   
  77.               
  78.             Phone_NoRec(PhoneNumber) '写入无录音记录  
  79.               
  80.         End if 
  81.  
  82.         While Not Rs.EOF  
  83.               
  84.             recname = Rs.Fields(1).Value  
  85.               
  86.             '组合新的文件路径  
  87.             DestFile = DestFloder & "\" & Right(recname,Len(recname)-Len("E:\VOICE_FILE\20100629\"))  
  88.               
  89.             oFso.CopyFile recname,DestFile  
  90.                                       
  91.             WScript.Echo DestFile  
  92.               
  93.             Rs.MoveNext  
  94.               
  95.         Wend   
  96.       
  97.         Set Rs = Nothing   
  98.           
  99.         Set PhoneNumber = Nothing   
  100.           
  101.         Set DestFile = Nothing    
  102.       
  103.     Wend   
  104.       
  105.     Set StrFilter = Nothing   
  106.           
  107. End Function   
  108.  
  109.  
  110. Function Phone_NoRec(PhoneNumber)  
  111.       
  112.     Set objFile = oFso.OpenTextFile("d:\Phone_NoRec.txt",8,true)  
  113.       
  114.     objfile.WriteLine PhoneNumber  
  115.       
  116. End Function   
  117.  
  118.  
  119. Function NoRec_Operating  
  120.  
  121.     Dim StrSql,Start_Time,End_Time  
  122.       
  123.     Dim NoRec_File,objFile,PhoneNumber  
  124.       
  125.     NoRec_File = "d:\Phone_NoRec.txt" 
  126.       
  127.     Start_Time = "2010-06-16" 
  128.       
  129.     End_Time = "2010-06-30" 
  130.       
  131.     Set objFile = oFso.OpenTextFile(NoRec_File,ForReading)  
  132.       
  133.     StrSql = "select t.fcalled ,t.rec_filename from tf_cdr t where t.call_start_time between to_date('" 
  134.           
  135.     StrSql = StrSql & Start_Time &" 00:00:00','yyyy-MM-dd HH24:mi:ss')" & " and to_date('" & End_Time & " 23:59:59','yyyy-MM-dd HH24:mi:ss')" 
  136.       
  137.     StrSql = StrSql & " and t.rec_filename is not null and t.fcalled = '"   
  138.       
  139.     While Not objFile.AtEndOfStream  
  140.       
  141.         PhoneNumber = objFile.ReadLine  
  142.           
  143.         Set Rs  = adoConnection.execute(StrSql & PhoneNumber & "'")   
  144.           
  145.         If  Rs.EOF Then   
  146.           
  147.             WScript.Echo PhoneNumber,"没有录音"   
  148.               
  149.         End if 
  150.  
  151.         While Not Rs.EOF  
  152.               
  153.             recname = Rs.Fields(1).Value  
  154.               
  155.             '组合新的文件路径  
  156.             DestFile = "d:\rec\" & Right(recname,Len(recname)-Len("E:\VOICE_FILE\20100629\"))  
  157.               
  158.             oFso.CopyFile recname,DestFile  
  159.                                       
  160.             WScript.Echo recname  
  161.               
  162.             Rs.MoveNext  
  163.               
  164.         Wend   
  165.  
  166.        
  167.     Wend   
  168.       
  169. End Function  

 

你可能感兴趣的:(oracle,快速,职场,休闲,数据库操作)