将变量传递到 sql 加载程序 ctrl 文件中



我有许多csv文件,我需要使用批处理和sql加载器加载到数据库中,但现在我希望能够为每个csv动态更改ctrl文件中的csv文件名,这样我就不需要为每个csv编写ctil文件。

我需要有关如何在Powershell脚本中执行此操作的基本帮助

foreach ($file in Get-ChildItem -Path .csv -Name ) { if ($file -like '*Rank*') { sqlldr.exe userid/password@oracle control=ctrl_fb_file2.ctl data=$file log=log_file.log DIRECT=FALSE ROWS=1000 | Out-Null } if ($file -like '*Values*') { sqlldr.exe userid/password@oracle control=ctrl_file_1.ctl data=$file log=log_file.log DIRECT=FALSE ROWS=1000 | Out-Null } }

使用PowerShell管道将使代码更具可读性和性能:

gci -Path C:pathtofils*.csv | foreach {
switch -Wildcard ($file = $_.FullName) {
'*rank*'   { sqlldr.exe ...data=$file...}
'*values*  { sqlldr.exe ...data=$file...} 
}

最新更新