1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowerShellからSQLPLUSに引数を渡してCSVを出力する

Last updated at Posted at 2018-12-18

タイトル通りの備忘録

例)oracleに格納されている、ある月の売上を職員の人数分CSVファイルで出力したい。

#集計対象年月をキーボード入力させる
$Input = Read-Host "集計年月を入力:"
$Output = $Input
$array = @("職員1","職員2","職員3","職員4")

#職員の人数分ループさせる
$array | ForEach-Object -Process 
{
#SQLファイルを読み込む場合は「`」が必要
#arrayから引数を渡す場合は「$_」
SQLPLUS hoge/hoge@hoge `@集計.sql $Output,$_
}

#sqlファイル内で拡張子をcsvとしたが、lstファイルが出力されるため、csvに変換
Get-ChildItem -Name | Rename-Item -NewName { $_ -replace "\.lst$", ".csv" }
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?