Dhruv Panchal
Dhruv Panchal

Reputation: 60

Importance of the cursor in DB2 stored procedure

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

Answers (1)

AngocA
AngocA

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:

  • A variable
  • A cursor

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

Related Questions