2016-02-29 100 views
0

我需要將%字符轉換爲SQL查詢,並將其傳遞給Windows批處理文件。我的問題是這個角色沒有被考慮在內。批處理文件:將%字符轉義爲PostgreSQL查詢

towns=(12232, 12233) 

for %%a in %towns% do (

    "C:\Program Files\PostgreSQL\9.4\bin\pgsql2shp.exe" -h localhost -u thomas -P password thomas_db "SELECT * FROM schema.table WHERE code like '%%a%'" 

) 

我得到以下錯誤:

C:\batch><"C:\Program Files\PostgreSQL\9.4\bin\pgsql2shp.exe" -h localhost -u thomas -P password thomas_db "SELECT * FROM schema.table WHERE code like '12232'"> Initializing... ERROR: Could not determine table metadata

LIKE '%%a%'被解釋爲LIKE '12232'和應爲LIKE '12232%'

+0

'喜歡 '%#%一%' 逃跑 '#'' – jarlh

回答

1

雙百分號轉義的百分比,從而加倍起來:

... WHERE code like '%%a%%%'" 
+0

這就是它!非常感謝@ Alex K. – wiltomap

相關問題