Unanswered: How to escape percent character in db2cmd?
I use db2cmd in DB2 v9.5 FP2a on Windows.
I did the following:
1. Open DB2 Command Window (db2cmd).
2. Set LANG variable with command: set LANG=en
3. Echo variable to see if it is set: echo %LANG%
Echo command should display "en".
4. Connect to database: db2 "CONNECT TO mydatabase"
5. Create table: db2 "CREATE TABLE ADMIN.MYTABLE (COL1 CHAR(10))"
6. Insert data: db2 "INSERT INTO ADMIN.MYTABLE VALUES ('LANG')"
7. Make select: db2 "SELECT * FROM ADMIN.MYTABLE WHERE COL1 LIKE '%LANG%'
Note: You see %LANG% is a variable in Windows command prompt, so instead of %LANG% value 'en' gets inserted.
8. Work-around on cmd I have deleted variable with command: set LANG=
9. If I re-execute select from step 7 and I get data from database.
The problem is I need LANG variable to be set to en, to make it possible to some of the program's batch (and some other programs) work correctly.
this helps if command is run from batch file for example to write to file:
db2 "SELECT * FROM ADMIN.MYTABLE WHERE COL1 LIKE '%%LANG%%'"
and then save it with myfile.bat and run it from command prompt.
But if I execute above command directly from command prompt then above double percent command does not work.
n_i, I have tried from command prompt and select returns empty result, the same if run from bat file.
As I see the only working solution without any hassle is to create ascii file and write:
SELECT * FROM ADMIN.MYTABLE WHERE COL1 LIKE '%LANG%';
save the file e.g. myfile.sql and run it using command:
db2 -tf myfile.sql
It is really interesting how Windows XP are primitive using command prompt comparing to some Linux distribution.