CURSOR

 

CURSOR data type is an object data type which stores the cursor identifier. A cursor can be declared implicitly without using the CURSOR data type - by means of the DECLARE statement. Such cursor has global scope of reference. Using the CURSOR data type to declare a cursor explicitly a programmer can specify any desired scope of reference in the same way like for any other variable. Thus a CURSOR variable defined in the GLOBALS file will have the global scope of reference and a variable defined within a function will have the local scope of reference.

 

CURSOR variables can be passed to functions and returned by them in the same way as the variables of simple data types. You should not assign values to variables of this data type using the LET statement, for it may cause unexpected behavior.

 

Both explicitly and implicitly declared cursors are mangled internally to ensure compliance with name size restrictions, and to ensure uniqueness. Use the CURSOR_NAME() function to retrieve the name of a cursor declared as a data type with the CURSOR variable as its argument.

 

A CURSOR variable can be used with the special methods which declare the cursor, open it, fetch the rows, etc. These methods are different depending on the type of the cursor (select or insert). The methods are called in the same way as other functions and are used together with the CURSOR variable in the following manner:

 

variable.Method()

 

The methods used with the CURSOR variable to create and process a select cursor are as follows:

 

An insert cursor needs a transaction to be opened first and then it will be typically used with the following methods: