Reason for using cursors in databases

-1

I understand what a cursor is, but I do not understand it and I can not get anyone to show me a real reason to use them.

Why should I use cursors? I want answers based on Oracle, SQL Server and MySQL and the difference in the use of cursors between them.

    
asked by anonymous 09.09.2017 / 18:37

1 answer

3

You know that cursors allow you to access the selected data for more or less free, that is, you create a set of stable data rows (keep the same rows) that you can rotate through them and do what you want. / p>

This is interesting because the data volume can be very large and loading everything can be a memory and load problem, so you can pick up the parts that interest you.

It is also useful because you may need to do complex analysis and processing that depends on code interactions as you "walk" through the data. In a way we can say that it can do streaming of the data. If it is something simple it is possible to do without cursors through the LIMIT and OFFSET clauses or similar alternatives of each database.

Some applications may need to receive data this way. Although it may bring inefficiencies.

It does not have to be this way, but it's usually more useful for DBAs or programmers who act like DBAs, in application queries the utility is less. Almost always the difficulties of using it correctly makes you think of a simpler and more reliable alternative.

Each database has its peculiarities, the question would be very wide to talk about the operation of each one.

    
09.09.2017 / 19:00