Reason for using cursors in databases

Asked

Viewed 258 times

0

I understand what a cursor is, but I don’t understand and I can’t 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 cursors use between them.

  • I find it more interesting to focus only on cursors (its would have so Generica) without quoting SGDB’s or focusing only on one. Asking everyone’s explanation can make the question broad.

  • Your question has become too broad.

1 answer

6


You know that cursors allow you to access the selected data more or less freely, ie you create a set of stable data lines (keeps the same lines) that you can circulate through them and do what you want.

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

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

Some applications may need to receive data in a specific way. Although it may bring inefficiencies.

Not that it needs to be like this, but it is 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 properly makes you think of a simpler and more reliable alternative.

Each database has its peculiarities, the question would be too broad to speak of the functioning of each.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.