I'm working with cursors whose behavior parameter is SCROLL
but I don't understand what the purpose of two of its functions is when doing the FETCH
.
I don't understand what they do or what they are used for FETCH ABSOLUTE and FETCH RELATIVE.
I'm working with cursors whose behavior parameter is SCROLL
but I don't understand what the purpose of two of its functions is when doing the FETCH
.
I don't understand what they do or what they are used for FETCH ABSOLUTE and FETCH RELATIVE.
As you know, the operator
FETCH
is used to extract rows from the resulting cursor according to the query that you have invoked, when you use the option as you say,SCROLL
it is used 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 option
SCROLL
, it is considered a unidirectional type cursor, which indicates that the result or the table of results that you receive from a certain cursor can only be traversed in one direction and by Therefore, each result of said cursor can only be read once at most.On the other hand, when declaring the option
SCROLL
, the resulting cursor or your results table will be able to read it in any direction thanks to the operatorsNEXT: 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: Read the cursor row indicating position "n" For example, if the cursor has 7 results:
and you define the following:
You will get the record (Result 2)
RELATIVE n: Read the record that indicates the value of "n" based on the row you are in. For example, given the previous situation, you are in row number 2 of the cursor and you define the following:
You will get the record (Result 5)
I hope the answer is helpful, in the same way take a read of this book, it is good and it clearly explains the operation of the cursors.
https://books.google.com.mx/books?id=vsYTINIEwd4C&pg=PT210&lpg=PT210&dq=para+que+sirve+fetch+absolute+sql+server&source=bl&ots=k1WdPvrqPP&sig=jkMSKjjm7MzTaMchZCnDWAEJULM&hl=es-419&sa=X&ved=0ahUKEwjxlP6GrNPbAhVROKwKHUYID20Q6AEIpwEwDg# v=onepage&q=for%20that%20serves%20fetch%20absolute%20sql%20server&f=false