Reputation: 60
I am working on db2 in my project but there is one question that, "Why do we declare cursor in the stored procedure". Can't we write stored procedure in DB2 without declaring a cursor?
Upvotes: 0
Views: 804
Reputation: 7693
Stored procedures are flexible and they can perform many tasks. If you want to deal with data you need one of the following things:
You can assign the value of a select into a variable, if the result is just one value
SET MAX = (SELECT MAX(SALARY) FROM EMP);
If you want to deal with multiple values from a result set you need a cursor, in order to fetch each row.
Upvotes: 2