I'm trying to pass a variable from my Powershell Script to SQLPlus.
I've defined my variable as $csvStorage (the file path to the folder "csv_files"):
Powershell Script:
# Set file path to C:xxxxxxxxxxxxxxxxcsv_files
$filePath = Split-Path -Path $directory -Parent
$csvStorage = Join-Path $filePath -ChildPath "csv_files"
I have then passed it as an argument to the SQL script:
Powershell Script:
# Run sql_queries.sql whilst passing C:xxxxxxxxxxxxxxxxcsv_files into the SQL script
$queryTables = "/c sqlplus $dbUsername/$dbPassword@$dbServiceName @$filePath $csvStorage"
&$sqlPlus $queryTables
Then finally, referenced the variable in my SQL using '&1':
SQL Script:
set null null
set heading on
set pagesize 50000
set termout on
spool &1hc_actual_vs_shadow_inv.csv
SELECT *
FROM hc_actual_vs_shadow_inv
/
spool off
/
exit
However, the query is not being executed and no .csv file is outputted. But I can't see what I'm doing wrong. Any assistance would be much appreciated.
Thanks
question from:
https://stackoverflow.com/questions/65672032/pass-a-variable-from-a-powershell-script-to-sqlplus 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…