我已经构建了一个powershell脚本,允许我运行并通过电子邮件发送从sql文件中读取的sql查询的结果:
function global:readscript($path)
{
#using UTF7 encoding to allow select with accented/french/russian/chinese/... etc chars
$inenc = [System.Text.Encoding]::UTF7
$reader = new-object System.IO.StreamReader($path, $inenc)
$finalquery = ""
while ($line = $reader.ReadLine())
{
$finalquery += $line
}
$reader.close()
return $finalquery
}
function global:get-result($query)
{
$oracleconnection = new-object Oracle.ManagedDataAccess.Client.OracleConnection
$oracleconnection.connectionstring = $connectionstring
$oracleconnection.Open()
$oraclecommand = $oracleconnection.CreateCommand()
$oraclecommand.CommandText = $query
$reader = $oraclecommand.ExecuteReader()
#...etc
}
$scriptquery = readscript "d:\mysqlquery.sql"
get-result($scriptquery)
到目前为止一切正常,除了这个包含" +"的sql脚本。用于计算的标志。
假设文件mysqlquery.sql包含一行,例如:
(SELECT COUNT(a.ID)) + (SELECT COUNT(b.ID))
我可以在控制台中看到它被翻译为
(SELECT COUNT(a.ID)) (SELECT COUNT(b.ID))
当然会抛出这个恼人的异常"缺少右括号"
从txt文件中读取加号时如何逃避加号?