(I have never done this myself but from reading the manuals, this is what you should do).
First you need to have the EXPLAIN tables created. See Appendix J in Vol 1 of the V8.1 SQL Reference manual, if they have not bee created.
Then you would create a script file something like:
EXPLAIN ALL SET QUERYNO = 13 SET QUERYTAG = 'MyQUERY ' FOR SELECT * from mytable;
-- get info from explain tables
SELECT * FROM EXPLAIN_STATEMENT WHERE QUERYNO = 13 and QUERYTAG = 'MyQUERY; '
-- any other SELECT statements against the EXPLAIN tables (see Appendix J again for layouts) that you may want
ARWinner, I know all of this! Ooooo, I haven't been clear enough. I would like to execute "explain sql" from sql file.
Now I have to write:
db2 explain all with snapshot for "select * from db2admin.test"
I would like to do this something like this:
db2 explain all with snapshot from sqlfile.ddl
I would like to have SQL statement in file! Now I must constantly convert multi row SQL statement to one row SQL statement to execute db2 explain from command line. That is time consuming. Any help will be appreciated.
ARWinner, I already have a script and I execute this script from batch file witch is executed from command prompt. But my script requires the SQL statement to be put in command prompt. So I just need somekind of option to execute SQL explain from file. BTW, the link you have provided doesn't show the explain option. It uses the reorg option I just don't need at this time.
n_i, I have tested "dynexpln" utility. The command is equal to "db2expln". It provides interesting output, but at the moment I don't need this option.
NOTE: My question is still the same: How to execute Explain from SQL file? Is it posible?