Questions tagged [cursors]

Cursors are used by database programmers to process individual rows returned by database system queries.

In computer science, a database cursor is a control structure that enables traversal over the records in a database. Cursors facilitate subsequent processing in conjunction with the traversal, such as retrieval, addition and removal of database records. The database cursor characteristic of traversal makes cursors akin to the programming language concept of iterator.

Cursors are used by database programmers to process individual rows returned by database system queries. Cursors enable manipulation of whole result sets at once. In this scenario, a cursor enables the rows in a result set to be processed sequentially.

In SQL procedures, a cursor makes it possible to define a result set (a set of data rows) and perform complex logic on a row by row basis. By using the same mechanics, a SQL procedure can also define a result set and return it directly to the caller of the SQL procedure or to a client application.

A cursor can be viewed as a pointer to one row in a set of rows. The cursor can only reference one row at a time, but can move to other rows of the result set as needed.

http://en.wikipedia.org/wiki/Cursor_(databases)

222 questions
2
votes
2 answers

SQL Server Cursor To Include the Value in Select

I have a SELECT statement returning a set of rows. From each row, I need to get a value of one column and pass it to a Stored Procedure to get a value that I would need to supply for the set of rows itself. For example: DECLARE @col1 int DECLARE…
Batuta
  • 1,614
  • 15
  • 42
  • 62
2
votes
1 answer

SQL Server query using a cursor

The query below calculates the percentage of a product between FY2009 vs. FY2010 for California. I am assigned to calculate the remaining states (Please see STATES table). Is there a way in SQL Server that could calculate the states percentages? I…
joe
  • 1,295
  • 6
  • 27
  • 42
2
votes
2 answers

TRS-80 POKE Cursor Table Smiley?

I'm trying to remember the POKE command to change the cursor on a TRS-80 Computer to a smiley face. POKE 16419,x will change the cursor. I cannot find a list of "x's"! I know that 255 gives a rocketship. Somewhere between 249-250 are gender…
rosepkid
  • 41
  • 3
2
votes
2 answers

Adapt Replace all strings in all tables to work with text

I have the following script. It replaces all instances of @lookFor with @replaceWith in all tables in a database. However it doesn't work with text fields only varchar etc. Could this be easily…
svandragt
  • 1,575
  • 19
  • 36
2
votes
1 answer

Function with cursor in postgreSQL

I want to make a Function in postgreSQL that reads the result of a query with a cursor and returns the result in a table. I am not very familiar with cursors but I have make an effort with no result. The output was a blank table. Here is my code:…
georgia
  • 31
  • 1
  • 2
2
votes
2 answers

call a stored procedure from the DECLARE statement when using cursors in MySQL

I am trying to use a cursor in MySQL to call a stored procedure many times. I want to call it as many times as a value for my_id exists in some temporary table, and iterate through those ids and concatenate the results. Anyway, I'm having trouble…
Monica Heddneck
  • 2,967
  • 5
  • 41
  • 77
2
votes
2 answers

Cursors in SQL Server

I have tried a lot of code but it has been useless. So, what I need is to set a cursor for a table that only has a complete name: create database DB01 use DB01 create table Clients ( complete_name varchar(50) ) insert into Clients values…
RalphVB
  • 103
  • 9
2
votes
0 answers

Custom cursor only shows briefly

In my project I use custom cursors, but those only show up for maybe a second and go back to the normal cursor. The elements are not overlaid by anything (Made sure of that with "pointer-events: none;" on overlaying elements). Here is the CSS I'm…
Ma. C.
  • 21
  • 2
2
votes
1 answer

Stored Procedure Syntax Error

I'm an admitted newbie with stored procedures. The following is generating a syntax error. "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3" CREATE…
tangollama
  • 21
  • 2
2
votes
4 answers

indexedDB - objectStore.openCursor() does not return all objects in the objectStore

I am trying to iterate on all the objects in my "product" objectStore using the openCursor() method. function getAllProducts(){ var products = []; var transaction = db.transaction(["product"], "readonly"); var objectStore =…
2
votes
2 answers

MySQL Cursor Issue

I've got the following code - this is the first time I've really attempted using cursors. DELIMITER $$ DROP PROCEDURE IF EXISTS demo$$ DROP TABLE IF EXISTS temp$$ CREATE TEMPORARY TABLE temp( id INTEGER NOT NULL AUTO_INCREMENT, start…
James Inman
  • 1,010
  • 4
  • 15
  • 30
2
votes
1 answer

For loop in python / arcpy SQL expression invalid, selection not working

I am creating a python script where I am trying to iterate over point feature class. I want to create seperate Feature classes from each individual day. So select daynumber and then export it to a new FC with an unique daynumber as name. I was…
Martijn
  • 31
  • 4
2
votes
2 answers

Sending one record from cursor to another function Postgres

FYI: I am completely new to using cursors... So I have one function that is a cursor: CREATE FUNCTION get_all_product_promos(refcursor, cursor_object_id integer) RETURNS refcursor AS ' BEGIN OPEN $1 FOR SELECT * FROM promos…
KacieHouser
  • 1,355
  • 3
  • 19
  • 31
2
votes
2 answers

Help replace this SQL cursor with better code

Can anyone give me a hand improving the performance of this cursor logic from SQL 2000. It runs great in SQl2005 and SQL2008, but takes at least 20 minutes to run in SQL 2000. BTW, I would never choose to use a cursor, and I didn't write this code,…
user318573
  • 113
  • 5
2
votes
4 answers

T-Sql cursor not proceeding on fetch

I know that cursors are frowned upon and I try to avoid their use as much as possible, but there may be some legitimate reasons to use them. I have one and I am trying to use a pair of cursors: one for the primary table and one for the secondary…
Aamir
  • 680
  • 3
  • 14
  • 25
1 2
3
14 15