Unanswered: when to use with as, when to use declare cursor for
I understand how DB2 internally operates with as and declare cursor for. As in the documentation stated:
1. with as is aiming the pre-select operation before the usually bigger select statment.
2. declare cursor for -> a real table stored temporarily. Often used to load statement.
So far so good. I am wondering what the real differences between the two, because I can make use of them vise and versa for my sql codes.
WITH-AS is a Common Table Expression (CTE) and is part of a select-statement. It can be used anywhere. A Cursor is a device for accessing the results of a query. DB2 may create one for a select statement internally. You can declare one if you wish to process the results set with SQL, for example.