Differences between FETCH ABSOLUTE and FETCH RELATIVE

1

I am working with cursors whose behavioral parameter is SCROLL but I do not understand what is the objective of two of its functions when it comes to making the FETCH .

I do not understand what they do or what they serve FETCH ABSOLUTE and FETCH RELATIVE.

    
asked by Sergio AG 14.06.2018 в 12:47
source

1 answer

1

As you know the operator FETCH serves to extract rows from the resulting cursor according to the query you have invoked, when using as you say the option SCROLL that serves to declare that the cursor of the resulting information will be multidirectional.

What does this mean? If you, when creating a cursor, do not declare it with the SCROLL option, it is considered a unidirectional type cursor which indicates that the result or the result table that you receive from a certain cursor can only be traversed in a single address and therefore each result of that cursor you can only read a single time as much.

On the other hand when declaring the option SCROLL the resulting cursor or your table of results you will be able to read it in any direction thanks to the operators

  

FETCH
            [[NEXT | PRIOR | FIRST | LAST
                      | ABSOLUTE {n | @nvar}
                      | RELATIVE {n | @nvar}
                 ]

NEXT: Read the next row, if you just started reading the cursor the result will be the first record of your cursor (only option for cursors NO SCROLL ).

PRIOR: Read the previous row.

FIRST: Read the first row of the cursor.

LAST: Read the last row of the cursor.

ABSOLUTE n: Reads the row of the cursor that indicates the "n" position For example, if the cursor has 7 results:

  Col1        Col2
 Resultado     1
 Resultado     2
 Resultado     3
 Resultado     4
 Resultado     5
 Resultado     6
 Resultado     7

and you define the following:

 FETCH ABSOLUTE 2 FROM cursor; 

You will get the record (Result 2)

RELATIVE n: Read the record that indicates the value of "n" based on the row in which you find yourself For example, given the previous situation, you are in row number 2 of the cursor and you define the following:

 FETCH RELATIVE 3 FROM cursor; 

You will get the record (Result 5)

I hope the answer is helpful, likewise read this book, it is good and clearly explains the operation of the cursors.

link

    
answered by 14.06.2018 / 16:53
source