database-cursor

How do I pass a date value to a cursor in plsql?

有些话、适合烂在心里 提交于 2019-12-10 10:25:47
问题 Basically I would like to pass a date value to a cursor, and print out the entire row/record after for each found. I am having trouble because a) I don't know if my date is being converted properly in the BEGIN section, and b) I am getting "wrong number or types of arguments in call to 'PUT_LINE'" when printing each row. This is what I have so far: DEFINE B_HIREDATE = 11-OCT-88 DECLARE cursor DATE_CUR (the_date DATE) is select * from employees where hire_date > to_date(the_date, 'dd-mon-yy')

What is an alternative to cursors for sql looping?

浪尽此生 提交于 2019-12-05 05:40:26
Using SQL 2005 / 2008 I have to use a forward cursor, but I don't want to suffer poor performance. Is there a faster way I can loop without using cursors? You can do a WHILE loop, however you should seek to achieve a more set based operation as anything in SQL that is iterative is subject to performance issues. http://msdn.microsoft.com/en-us/library/ms178642.aspx Here is the example using cursor: DECLARE @VisitorID int DECLARE @FirstName varchar(30), @LastName varchar(30) -- declare cursor called ActiveVisitorCursor DECLARE ActiveVisitorCursor Cursor FOR SELECT VisitorID, FirstName, LastName

ORA-00932: inconsistent datatypes: expected - got -

僤鯓⒐⒋嵵緔 提交于 2019-12-03 13:55:31
问题 I have been using Oracle(10g.2) as a PHP programmer for almost 3 years, but when I gave an assignment, I have tried to use the ref cursors and collection types for the first time. And I 've searched the web, when I faced with problems, and this ora-00932 error really overwhelmed me. I need help from an old hand. Here is what I've been tackling with, I want to select rows from a table and put them in a ref cursor, and then with using record type, gather them within an associative array. And

Solving Procedure with no parameters

冷暖自知 提交于 2019-12-02 09:50:20
Hey guys just here to see if you guys can help me solve this Procedure problem I am running into. Long story short I made a new table called Create Table ClientHistoricalPurchases( ClientID varchar2(6) constraint clientidhistorical references Clients, DistinctProducts number (9), TotalProducts number(9), TotalCost number (9,2), Primary Key (ClientID)); And I want to populate/update this table by running a procedure that reads primarily from the following table: create table OrderDetails( OrderID varchar2(6) CONSTRAINT orddetpk PRIMARY KEY, ProductID varchar2(6) CONSTRAINT prdfk REFERENCES

Can I reset cursor's position to the beginning?

て烟熏妆下的殇ゞ 提交于 2019-11-30 08:11:26
As in the topic. Can I simply reset cursor's position to the beginning in Transact-SQL, so it can run again over the table? I want to reset it in the following context: DECLARE @userID INT DECLARE user_cursor CURSOR FOR SELECT userID FROM users WHILE /* some condition */ BEGIN ... FETCH NEXT FROM user_cursor INTO @userID IF @@FETCH_STATUS = 0 BEGIN /*... here goes the reset of the cursor ...*/ END ... END you need to declare your cursor as scroll, like this declare c scroll cursor for (select statement); then at any time for locating to the first just use the following fetch first from c;

What is the use of a cursor in SQL Server?

别等时光非礼了梦想. 提交于 2019-11-30 01:34:45
I want to use a database cursor; first I need to understand what its use and syntax are, and in which scenario we can use this in stored procedures? Are there different syntaxes for different versions of SQL Server? When is it necessary to use? Cursors are a mechanism to explicitly enumerate through the rows of a result set, rather than retrieving it as such. However, while they may be more comfortable to use for programmers accustomed to writing While Not RS.EOF Do ... , they are typically a thing to be avoided within SQL Server stored procedures if at all possible -- if you can write a query

Can I reset cursor's position to the beginning?

你离开我真会死。 提交于 2019-11-29 11:12:45
问题 As in the topic. Can I simply reset cursor's position to the beginning in Transact-SQL, so it can run again over the table? I want to reset it in the following context: DECLARE @userID INT DECLARE user_cursor CURSOR FOR SELECT userID FROM users WHILE /* some condition */ BEGIN ... FETCH NEXT FROM user_cursor INTO @userID IF @@FETCH_STATUS = 0 BEGIN /*... here goes the reset of the cursor ...*/ END ... END 回答1: you need to declare your cursor as scroll, like this declare c scroll cursor for

What is the use of a cursor in SQL Server?

£可爱£侵袭症+ 提交于 2019-11-28 22:23:08
问题 I want to use a database cursor; first I need to understand what its use and syntax are, and in which scenario we can use this in stored procedures? Are there different syntaxes for different versions of SQL Server? When is it necessary to use? 回答1: Cursors are a mechanism to explicitly enumerate through the rows of a result set, rather than retrieving it as such. However, while they may be more comfortable to use for programmers accustomed to writing While Not RS.EOF Do ... , they are

Cursor For Loop with dynamic SQL-Statement

断了今生、忘了曾经 提交于 2019-11-27 23:20:18
Is there a way to perform a Cursor For Loop with an dynamic SQL-statement? If I don't want to declare a record I can do something like this (only if I declared the cursor..): For I in cuSelect Loop dbms_output.put_line(I.NAME); End Loop; And I can open a cursor for a dynamic SQL-statement: Open cuSelect For 'Select * From TAB_X'; Fetch ceSelect Into recSelect; Close cuSelect; But to do that I have to first declare the Record. Now my problem is that I have to open the Cursor for a very big and complicated dynamic SQL-statement. The structure of the record is unknown. Is there a way to open a

Using a cursor with dynamic SQL in a stored procedure

断了今生、忘了曾经 提交于 2019-11-27 03:15:17
I have a dynamic SQL statement I've created in a stored procedure. I need to iterate over the results using a cursor. I'm having a hard time figuring out the right syntax. Here's what I'm doing. SELECT @SQLStatement = 'SELECT userId FROM users' DECLARE @UserId DECLARE users_cursor CURSOR FOR EXECUTE @SQLStatment --Fails here. Doesn't like this OPEN users_cursor FETCH NEXT FROM users_cursor INTO @UserId WHILE @@FETCH_STATUS = 0 BEGIN EXEC asp_DoSomethingStoredProc @UserId END CLOSE users_cursor DEALLOCATE users_cursor What's the right way to do this? cmsjr A cursor will only accept a select