Even though we are advised not to use or to minimize the usage of cursors in SQL, there are times which, it’s the only available option, depending on the task and the situation. But there are times you are required to build the cursor using a dynamic SQL select statement.
To illustrate this, i will create two tables and populated it with sample data.
When creating a cursor using dynamic query, initially the cursor should be declared and passed on to the dynamic query execution.
Also you can create a procedure which will return you a cursor taking the selection query as a parameter.
Use the following syntax to use the above mentioned procedure