SQL Cursor : Database Object That Provisions Access to Records in a Database

learn more… | top users | synonyms

2
votes
1answer
55 views

How to show when loan was paid off

First time posting but have been a reader for over 10 years. I have a need to show when a loan was paid off regardless of the rolling balance from refinancing/taking out additional loans. In the ...
0
votes
0answers
16 views

PostgreSQL 9.5, getting “cached plan must not change result type” error

I had a really odd and unexpected behaviour in PostgreSQL. Debugging I found that the problem only occurred while including CREATE TEMP TABLE ... inside a function, and by using an alternative (in ...
3
votes
1answer
67 views

Adding an ID column based on two other columns

I have a query which returns output as follows: [Location] [Reference] [Year] [Int1] [Int2] England 1 2015 13 201 England 1 2015 12 57 England ...
2
votes
1answer
49 views

RedGate SQL Prompt - Cursor Snippet mistake

Using RedGate's SQL Prompt & loving it. But I used the "curff" snippet for the first time today ("Fast-forward read-only cursor"), and it produced the following TSQL (which I've filled in to make ...
3
votes
1answer
55 views

Converting SQL SERVER Procedure to POSTGRESQL

I have procedure in SQL Server to print all players of given country. I try to convert it into plpgsql, but I get errors. SQL Server Procedure CREATE PROCEDURE kraj_pilkarze @kraj varchar(30) AS ...
0
votes
1answer
23 views

Procedures In Oracle [closed]

--Procedures Exercise: create or replace procedure Display is cursor ABC is select empno, ename, sal from emp where deptno=10; emp_rec ABC%rowtype; Begin Open ABC; Loop fetch ABC into emp_rec; exit ...
0
votes
2answers
86 views

Search entire database

Recently I was working on the database of an application that had no documentation and the database did not have any foreign keys. I needed to create a script to enforce a 10 year retention policy. It ...
0
votes
0answers
14 views

Help with logic with cursor

I have a table called chapter_element, that houses the content for a web ebook. (There are other tables, but this is where the content is contained.)This is the table structure. CHAPTER_ELEMENT ...
2
votes
1answer
142 views

Is it possible to disable use of fast forward-only cursor on server side?

I have an application that is using ODBC to access a SQL Server 2012 database using SQLSetStmtAttr to set the SQL_SOPT_SS_CURSOR_OPTIONS option to SQL_CO_FFO. This means that its reads from the DB are ...
0
votes
3answers
107 views

How to get currently inserted rows and sum them within Mysql trigger before insert

I have a mysql trigger that fires BEFORE INSERT. My php application is inserting multiple rows at once like so INSERT INTO table1(id,name,price) VALUES(1,'LH32400', 1990),(2,LH32401,2000); The idea ...
6
votes
2answers
175 views

SQL Server using index scan instead of seek when updating a view that has an INSTEAD OF UPDATE trigger via a cursor

I have a 3rd party application which uses a cursor that updates rows in my SQL Server 2014 table. I am unable to modify this code and have therefore devised a scheme to point the cursor to a view ...
1
vote
1answer
52 views

Determine structure of out cursor

I have a function in Oracle that neither I nor my team wrote and is heavily obfuscated. However, it has a cursor out parameter. How can I find out the number and types that the cursor contains? For ...
1
vote
0answers
46 views

Is it possible to tail a log with a cursor?

I thought the DYNAMIC keyword would work but it doesn't seem to. Basically I have an ASP.NET Application using the log4net AdoNetAppender. I'd like to be able to SELECT * FROM Logging.Logging in a ...
2
votes
1answer
58 views

Does @@FETCH_STATUS have (or need) an equivalent to SCOPE_IDENTITY?

MSDN advises that @@FETCH_STATUS be used with care because it's global: Because @@FETCH_STATUS is global to all cursors on a connection, use @@FETCH_STATUS carefully. After a FETCH statement is ...
1
vote
1answer
58 views

Does the function inside the Select clause evaluate the passed in columns before the where clause?

I have a simple select statement that uses a (not so) simple function. I'll try to simplify and demonstrate to the best of my abilities for purposes of this question. select ...
1
vote
3answers
285 views

Improve a query using cursor to SET Based approach

I am still new to Query optimisation, and I have a Stored Procedure which uses a Cursor to go through each row within the Table, and performs the following operations: Calculate the Time Difference ...
1
vote
0answers
54 views

How to use set-based statement instead of cursor for converting 1 table to two, keeping relations

I'm relatively new to databases and currently working with SQL. I am doing a conversion for a customer. This conversion points to local files on a filesystem. In the old database there simply was a ...
3
votes
2answers
333 views

Pass (comma separated) -yet single parameter to cursor

I have to get selection for a given string (with comma separated values) passed to the cursor. There can be multiple values that could be passed via single variable. My code is somewhat like: CURSOR ...
3
votes
1answer
62 views

DB2 Dynamic Load from cursor

We have to load a number of huge tables using Load From cursor. The query formed for the same is a dynamic query as the column names are to be specified. we do the same using the below code in a ...
1
vote
1answer
115 views

DB2 : Load from cursor Dynamic query

We need to move multiple tables using Load from cursor. But the number columns in the source and destination tables are not the same. Also the tables structures can change so we need the same to ...
0
votes
0answers
78 views

Filtering with cursor pagination

We're using cursor pagination as described in this article over a large dataset using PostgreSQL and Django Rest Framework. I'm trying to get a better understanding of the internals of this to solve ...
1
vote
1answer
122 views

Cursor with Begin and End Transaction

I've got the following script that keeps hanging on the 2nd iteration through the loop. BEGIN BEGIN TRY BEGIN TRANSACTION DECLARE @itemID int DECLARE LoopCursor CURSOR FOR ...
0
votes
0answers
29 views

Mysql Procedure insert one to many with cursor

I would like to take a course, or just show me the way. There is a table called Questionario from it I get the records in a procedure and organize the data into it. Here is my code:      CREATE ...
-1
votes
1answer
115 views

Error with Loop using Cursors - Invalid Object Name with Set = @

Working on a script to Loop through databases to query one table that each Identical Database has with cursors then return result set to table for each database. I think I have the structure for Set @...
4
votes
2answers
2k views

Can two sessions create #temp tables with the same name?

I am creating a temporary table (#myTable) and using a cursor. Does this create a problem when concurrent users are accessing the cursor through my application? Does it allow me to create separate ...
0
votes
1answer
326 views

Dynamic SQL To Send HTML Email

I am creating a cursor to iterate the values stored in my table, then attempting to use dynamic sql to set the select statement for my html body email. However, anytime I try to execute my statement ...
0
votes
1answer
45 views

INSERT from SELECT using a CURSOR

I have a table that looks like this: +====================================================+ | aid | uid | eid | name | dob | paid | +====================================================...
8
votes
3answers
522 views

Lots of “FETCH API_CURSOR0000…” on sp_WhoIsActive ( SQL Server 2008 R2 )

I have a strange situation. Using sp_whoisactive I can see this: Ok, with this query, I can see what is triggering ( does this word exists in english? ) it: SELECT c.session_id, c.properties, c....
1
vote
1answer
3k views

How to FETCH from a cursor into a table variable?

I have a cursor defined as: DECLARE idCursor CURSOR FOR SELECT DISTINCT [id], [data] FROM #tempTable And I have a variable defined as: DECLARE @currentId TABLE ( ...
2
votes
1answer
3k views

Get values from Select statement and Insert them in Temp table Stored procedure [closed]

Here is my stored procedure. I want to select data from a table, save it in a variable then insert in other variable. However, my select statement has where. In it the value for the day should come ...
0
votes
2answers
171 views

Auto increment a value using cursor in SQLServer

I am developing an employee leave management system and My table structure with data is : +-----------+---------+----------+----------+------------+--------------+ | EmpID | CL | PL | ...
8
votes
1answer
454 views

sp_cursoropen and parallelism

I'm running into a performance problem with a query that I can't seem to get my head around. I pulled the query out of a cursor definition. This query takes seconds to execute SELECT A.JOBTYPE FROM ...
3
votes
2answers
167 views

Stored procedure using cursors [closed]

I am attempting to create a procedure using cursors to list the average salary of all employees on a per department basis. I am using three tables, defined as emp (eid, ename, age, salary) works (...
1
vote
1answer
33 views

Update Using a cursor

I know that instead of cursor we can have the tables updated with different queries but I wanted to try using cursor so as to have a knowledge on cursor This was what I was trying I have inserted a ...
2
votes
1answer
87 views

What is a cursor?

I am new to database concepts and I found some sources that try to explain what is a cursor, but I can't understand what they mean. Can someone explain in a very basic manner what a cursor is and what ...
0
votes
1answer
112 views

Replacing a Cursor with a single Query possible?

I have this challenge where I'm trying to figure out if I can write something in a single query rather than using a cursor. The problem is I need to get items from a batch table based on a list of ...
0
votes
0answers
78 views

How can I replace the cursor in the below query?

I have this below query which calls a stored procedure that takes only 1 item's attributes at a time. But because of performance problems we are required to remove the cursor. How can I replace the ...
1
vote
1answer
95 views

Cursor Performance in New Server

I bought a new server with spec : HP ProLiant ML310e Gen8 v2 8 GB Single Memory, Intel Xeon E3-1220v3 3,1 GHz, 500 GB SATA 7.5K RPM, Windows Server 2012 R2 x64, SQL Server Standard 2014 x64, RAID 0 ...
3
votes
1answer
159 views

SQL Server index causing incorrect behavior on cursors

I have a SQL Cursor that's behaving incorrectly as soon as we added an index to a table. Here's a trimmed-down example of the query causing issue: DECLARE @CUR_CRDATE NVARCHAR(8) DECLARE ...
0
votes
0answers
386 views

Mysql cursor alternative / Optimization - each row updates are too slow

I'm looking to optimize my cursor based update or actually replacing it... Situation We're carrying out promotional campaigns and I'd like to track user activity per campaign. Logic Each campaign ...
2
votes
1answer
1k views

T-SQL CTE Compare previous non-NULL and current row to filter out by difference value

My sample database (in fact a CTE statement data) looks like this: eventdate val 2012-03-23 3965 2012-03-26 3979 2012-03-27 3974 2012-03-28 3965 2012-03-29 3967 2012-03-30 3959 2012-04-02 ...
1
vote
1answer
4k views

SELECT from Function that return CURSOR

I would like to select from a function that return a SYS_REFCURSOR Type value. for example : CREATE OR REPLACE FUNCTION my_funtion ( my_param IN VARCHAR2) RETURN SYS_REFCURSOR IS ...
0
votes
1answer
150 views

Modifying a result set in a Stored Procedure, then returning that modified set

I am currently in the process of designing my database for a mobile/web application. When I look at competing apps I see a massive flaw in how they handle user locations. Due to the nature of the ...
0
votes
1answer
2k views

Compare two big tables in PL/SQL

I need to implement comparing 2 tables by set of keys (columns of compared tables). By this comparing i should check equal records (equal = equal by set of defined keys (columns in these input tables))...
3
votes
1answer
3k views

Why choose a top query and temporary table instead of a cursor for a loop?

When it comes to looping over a large set of data in T-SQL, the majority of examples I see on the Internet use a pattern like this: declare @someVariable int declare @remainingRows int select ...
4
votes
4answers
895 views

Keep track of time intensive stored procedure with prints

I am no database admin nor is my SQL-foo any good (yet), but have a few tasks to get done in MSSQL, and one is a rather time intensive procedure where I fetch from a CURSOR and WHILE @@FETCH_STATUS = ...
2
votes
1answer
77 views

PLSQL using cursors or functions to query repeated data

Is it better to declare a commonly used lookup query as a package function or as a function (either returning rows or values or returning a sysref cursor)? Whats the difference? What are the best ...
0
votes
2answers
224 views

Update specific records of table based on subquery's output (sql server)

have this query which produce below output : select sec.site,sec.Name,sec.Freq from ( select Name from sec group by name having count(Freq) > 3)as dt inner join sec on dt.Name = sec.Name where sec....
0
votes
0answers
19 views

Curious Regarding filtering behaviour and performance of where condition

So i have completed the clean up of SQL code that involves four set of queries that partially do the same filtering in where condition , while the rest of the part do their own task specific to each ...
3
votes
1answer
2k views

Converting Cursor based filtering logic to CTE based

I have a cursor that runs long for about minutes which I was able to reduce to run in seconds using a CTE (Common Table Expressions). The result set was identical until there was given a condition ...