July 27th, 2009

Host Programs, Cursor Control (Part 1 of 2)

Posted by admin in S. Host Programs

SQL is called non-procedural. That means it operates on an entire table or set of tables returning zero, one, or many rows. With one query, you can get thousands of rows returned at one time.Most application languages are procedural, which means they are a procedure that handles one table row and then loops to process the next table row. A cursor, when it is active, is like a pointer that allows SQL to retrieve, insert, update, or delete a single row. The cursor retrieves a row from a table and hands it to the procedure for processing. This way, you can process the entire result table one row at a time.

The procedural application invokes the SQL and, for this reason, it is called the host program.
A typical procedure flows something like this:

          Procedural code
          EXEC SQL DECLARE CURSOR statement
          EXEC SQL OPEN cursor statement
          Test for end of table
          Procedural code
          Start loop
               Procedural code
               EXEC SQL FETCH
               Test for end of table
               Procedural code
          End loop
          EXEC SQL CLOSE cusror statement
          Procedural code

Leave a reply

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad: