Questions tagged [database-cursor]
Use this tag for programming-related questions about database cursors. If your question is specific to a particular database, tag the database type too.
845
questions
0
votes
2
answers
50
views
SQL cursor take too long to complete
DECLARE
orderid NUMBER;
customerid NUMBER;
channel VARCHAR2(20);
amount NUMBER;
CURSOR orders_cursor IS
SELECT
order_id,
customer_id,
channel,
FINAL_PROFIT(...
0
votes
1
answer
34
views
Loop all the tables using cursor
I have a some set of 4 tables policy table, coverage table, vehicle table and driver tables.
Policy table example
policy number
record lauyout
Abc
polr
Efg
polr
Coverage table example
Policy ...
1
vote
1
answer
38
views
CURSOR seems empty but SELECT returns non-empty data
I have a mysql Procedure for awarding allowances to socially active students. In this Procidure I'm updating Students table. Inside this procedure I have define a cursor which gives 2 values (...
0
votes
0
answers
35
views
"commands out of sync; you can't run this command now" on first use of cursor
I am using MySQL in Django (Python).
The draft version of this code worked and was stable, but it created cursors without closing them, and I just rewrote it to manage the cursor with enter/exit. Now ...
-1
votes
1
answer
57
views
On what criteria can While loops and Cursors be compared? [duplicate]
Suppose that I have a query that really must be either a cursor or a while loop. What criteria can be used to judge which should be used?
Notably not a duplicate of this question. I'm not trying to ...
0
votes
4
answers
64
views
pl/sql : Error when declaring a cursor in exception section
What is wrong with this function please : i'm getting this error : Encountered the symbol "CFCE" when expecting one of the following:= . ( @ % ;
Note : when i declare the cursor in the ...
0
votes
0
answers
15
views
How to copy values from a table into another table during PostgreSQL EF migration?
I use ASP.NET, PostgreSQL and Entity Framework.
I have to copy current values of the sequences I use into a new table.
Creating new table during migration is obvious. Then I can acquire all sequence ...
0
votes
1
answer
45
views
How do I update mutiple rows of a table using Cursor loop?
I have 3 database located in different schema, lets call it
source_schema.target_table
target_A.target_table
target_B.target_table
and wanted to move data from table source_schema to target_A, ...
0
votes
0
answers
43
views
Pyodbc cursor.fetchall() alternative
I am trying to build a dataframe in python with the result of a query in a MSSQL database. For now I load the result in a list res = cursor.fetchall(). The problem is that the result contains more ...
0
votes
1
answer
80
views
Create function to return results from multiple queries
I am struggling to write a function to return data from more than 1 table in Postgres
CREATE TABLE IF NOT EXISTS dbo.device (
deviceid uuid NOT NULL,
serialnumber character varying(255),
...
0
votes
0
answers
36
views
Python pypyodbc cursor (data) to excel sheet
I have obtained a cursor (data recordset) from sql server using pypyodbc. I have xlwings library and have spawned a workbook. I can simply loop through each row of the cursor and write the fields of ...
1
vote
2
answers
27
views
Can nonrepeatable reads / phantom reads occur with PostgreSQL's cursors?
When paginating without cursors, it's possible to see phantom reads. E.g. paginating over a large set of data like so:
// assume isolation level = READ COMMITTED
SELECT * FROM users ORDER_BY age ASC ...
0
votes
0
answers
17
views
Python-SQL Error : Commands out of sync; you can't run this command now [duplicate]
I am facing the error mentioned in the title when I try to run this code. (this is a part of a bigger project).
Basically, for some reason, it is not allowing me to insert rows into my table after ...
1
vote
2
answers
52
views
Cannot find official Oracle doc for cursor+ select for update skip locked
I'm using Oracle 19c.
In a concurrent environment, when I want to lock a single row I do the following
DECLARE
CURSOR cur IS
SELECT id, name
FROM sample
ORDER BY id ASC
FOR UPDATE SKIP ...
1
vote
1
answer
88
views
Python - Get result of an update query (Mysql) when performing raw SQL
I work on a Django project and need to apply changes in an other remote DB (not Django DB).
Those changes are async and launched with Celery. But when performing these queries, I need to know if ...
1
vote
1
answer
40
views
Snowflake function with variable as parameter
I am trying to find out the object level dependencies (tables and/or other views) of the views created in my work schema.
My userid/role does not have access to ACCOUNT_USAGE because of organizational ...
0
votes
0
answers
179
views
Snowflake Python Connector - fetch_pandas_all() is really slow with less than 25k records
I'm using fetch_pandas_all function to retrieve result of a query that takes less than 2 sec in Snowflake (checked activity in UI) but the function itself takes like 30 seconds - we are talking about ...
1
vote
1
answer
89
views
Dump current open cursors when a ORA-01000 maximum open cursor error occurs
Our backoffice sporadically suffers from ORA-01000 maximum open cursors error (The few time it happened was weekends when nobody work).
Is it possible to dump the details on open cursors in a table ...
0
votes
1
answer
96
views
Cursor Loop in a PL/SQL Procedure that updates data
I'm currently trying to learn PL/SQL. Right now I'm trying to understand how can I use cursor loop in a procedure that updates data.
Example scenario: Create a PROCEDURE, to update the schedule_code ...
0
votes
0
answers
16
views
Error using cursor.getColumnIndexOrThrow to access Media Images
I'm trying to access the MediaStore.Images file using cursor but it keeps giving an error .
I tried creating an image object containing an array of images in the device, nd load it to the screen using ...
0
votes
1
answer
44
views
How to define a list with data similar to the result of a Snowflake cursor.description?
cursor.execute("select * from table)
desc = cursor.description
print(desc)
[ResultSetMetadata(name='id', type='', prescision=20 ...),ResultSetMetadata(name='name', type='', prescision=20...)]
...
0
votes
2
answers
123
views
How can I check if the cursor is empty?
I have the following sp, where I want to respond to the cursor in case an error does not occur (that's ok) but in the case that it has no rows or is empty, I would like to respond with a code with a ...
0
votes
2
answers
40
views
Loop Through DB, get table dependencies inquiry
Goal
Use Table Cursor to loop through all tables within schema and get table dependencies.
I want to use it like this
DECLARE @SchemaName nvarchar(MAX)
DECLARE @TableName nvarchar(MAX)
...
0
votes
1
answer
49
views
How to show a username + column_time using an SQLite cursor
Right now, I'm confused with the SQLite cursor. Before I made it using the recyclerview method, but in my code it uses a cursor.
I can't show the column, and I'm confused what should I add.
In my case ...
0
votes
0
answers
26
views
Looping through a database's schemas using Dynamic SQL Via Postgresql
Sorry I had to edit this to account for new information. However what I am trying to do is the same as before. I am trying to basically loop through specific schemas within the same database and ...
2
votes
0
answers
93
views
IndexedDB update multiple record
I am using indexedDB, and I have a orderProductIndex index inside the order_items collection. The index is not unique!
What I want to do is, select every record from the index with a specific id, and ...
1
vote
0
answers
50
views
How to fix syntax error in sql column change with cursor?
I want to change multiple column names but I'm getting a syntax error around the + in sp_rename and I don't know how to fix it. I've done so much googling already :(
This is the first part of my code.
...
4
votes
1
answer
95
views
T-SQL bug? CURSOR does not respect TABLESAMPLE
Ran into this today. Code as follows, with tablesample commented out. Run it, get the expected results of 5000050000.
-- tested in SQL Server 2014
use tempdb;
IF OBJECT_ID('dbo.ints', 'U') IS NOT ...
0
votes
0
answers
23
views
What is the correct way to implement cursor inside procedure in mysql? [duplicate]
DELIMITER $$
CREATE PROCEDURE updstock (IN item_id int, IN issue_qty int)
proc_label:
BEGIN
DECLARE av_stock INT DEFAULT NULL;
SET av_stock = (
select
sum(qty)
...
0
votes
1
answer
75
views
How, in PostgreSQL, can I iterate through table A, and use a column from table A as a limit for a join to table B to populate table C
Working with Greenplum 6 (based on PostgreSQL 9.4.), I have these
sample tables:
Table SAMPLE_A:
| uniqueId | SampleSz |
| -------- | -------- |
| 1 | 25 |
| 2 | 50450 |
| 3 ...
0
votes
0
answers
31
views
Clang.cindex to find variable names in c++ code
I have to use cursors to find mutex names in c++ code. When run it appends "class std::mutex" to self.mutex names.
def analyse_cursor(self, cursor: clang.cindex.Cursor) -> List[Alert]:...
0
votes
0
answers
82
views
Cursor based pagination and sorting
I´m learning server side pagination, ans specifically cursor based pagination.
Currently I´m trying to implement it on my data base. After doing some readings, I understood that data needs to be ...
0
votes
1
answer
77
views
Return next date
I have a table with 2 columns and I need to calculate the next_report_date based on the information of Frequency and Created_date.
Functional description is: it should always be the upcoming Wednesday ...
1
vote
1
answer
107
views
Trying to Loop via Cursor Through Partition Selection Until Counter Value is Satisfied
I understand that there are other potential options and a cursor may not be the most efficient choice for what I'm trying to accomplish, but be that as it may I'm hoping to gather some guidance on how ...
0
votes
0
answers
185
views
Looping with Redshift Cursor and updating variables to include all row data
After hours of searching, I still haven't found a workable solution to my problem. I have a semi working solution, but need a little help getting is complete.
I have a seed table that has the ...
0
votes
1
answer
259
views
T-SQL loop for inserting data with incrementing id
I have this T-SQL procedure to store the result of a query in my database. This query could extract more than a result therefore I need to create a counter to insert row by row at correct id value:
...
0
votes
1
answer
460
views
Using cursor to insert data from on table to another but inserting only first row
there are 2 table (capacitymaster2 , #CapacityInsertData) I want to check some condition and insert to capacitymaster2 .
Note : #CapacityInsertData has 3 row where all data satisfies the condition ...
1
vote
1
answer
193
views
SQL Cursor not working with where not equal
`Hi everybody,
My target is to update a field of a table (TABLE1) which has different values from its master table (TABLE2) with a SQL Procedure.
The select is working (giving about 20 results) but ...
0
votes
2
answers
129
views
Closing cursors and exception
What is the "correct" way to deal with exceptions in a code block using a SQL cursor ?
Is it necessary/recommended to close the cursor and the database? If so, what is the correct way to do ...
0
votes
1
answer
177
views
sp_cursoropen returns empty result set when the query works fine
While migrating from Advantage database to SQL Server using OLEDB providers, a part of my application stopped working. After investigation I have found that the application freezes when I try to ...
0
votes
0
answers
193
views
How to run SQL query in loop for different databases in Snowflake
I have a table containing about 200 database names within my Snowflake, all having table named XX.
I want to search for specific value inside a specific column, so lets say is somthing like this
...
0
votes
2
answers
30
views
I need to sequence a Num_Linea column, but the sequence must be restarted for each ID_PO
Currently the cursor does the sequence but does not restart when the ID_PO is different.
DECLARE @Num_Line as int;
DECLARE @CurNum_Line as int;
SELECT @Num_Line = 1;
DECLARE LINECURSOR CURSOR FOR
...
0
votes
2
answers
396
views
Send an email for every row in a table in SQL Server
When trying to send an email per row using this code, I'm getting one email per relevant row. However, each email only contains the value of the first row:
DECLARE @BCC VARCHAR(MAX) = ''
DECLARE ...
0
votes
1
answer
120
views
Redshift procedure - Error returning result as cursor
I am trying to return a cursor from a procedure:
CREATE OR REPLACE PROCEDURE sp_my_test_sp
(
rs_out INOUT refcursor
) as $$
BEGIN
OPEN rs_out FOR
select 'TestValue'...
-2
votes
2
answers
109
views
Split field and insert rows in SQL Server trigger, when mutliple rows are affected without using a cursor
I have an INSERT trigger of a table, where one field of the table contains a comma-separated list of key-value pairs, that are separated by a :
I can select this field with the two values into a temp ...
0
votes
0
answers
33
views
How to use Ids returned from a mysql query inside another query in Python
New to python so need some help.
I have a mysql query which I execute using a cursor as below:
qresult = cursor.execute('SELECT * FROM questions WHERE category_id=%s, (category_id))
questionslist = ...
0
votes
1
answer
84
views
Saving table stats into a table, including the table name
I'm running into a wall compiling row updates and new rows in a few tables to save off in another table for trending. I know a cursor could achieve this pretty easily and I get a result set, but I'm ...
0
votes
0
answers
61
views
SQL Cursor and Email
I have a cursor in place that needs to send an email to one person containing all the rows associated with a certain field
To explain a bit further, i have a table which contains multiple rows, with ...
1
vote
2
answers
99
views
How to access different columns of a different tables using cursor after a join has been made on a particular column name in the tables
So I am having issues in understanding how can one access different column names using a cursor in which a join operation has been made on three different tables over a single common column.
For ...
-1
votes
2
answers
140
views
Is there a way to loop function in SQL Server
I'm trying to write queries that can loop new columns to selected number, such as 100 or 200 new columns, which use data from the previously created columns.
I have data like below:
IF NOT EXISTS
(
...