what is cursor procedure
Answer / manoj kaushik
/* Same as previous example, this time using a
** cursor. Each update commits as it is made.
*/
create procedure increase_price_cursor
as
declare @price money
/* declare a cursor for the select from titles */
declare curs cursor for
select price
from titles
for update of price
/* open the cursor */
open curs
/* fetch the first row */
fetch curs into @price
/* now loop, processing all the rows
** @@sqlstatus = 0 means successful fetch
** @@sqlstatus = 1 means error on previous fetch
** @@sqlstatus = 2 means end of result set reached
*/
while (@@sqlstatus != 2)
begin
/* check for errors */
if (@@sqlstatus = 1)
begin
print "Error in increase_price"
return
end
/* next adjust the price according to the
** criteria
*/
if @price > $60
select @price = @price * 1.05
else
if @price > $30 and @price <= $60
select @price = @price * 1.10
else
if @price <= $30
select @price = @price * 1.20
/* now, update the row */
update titles
set price = @price
where current of curs
/* fetch the next row */
fetch curs into @price
end
/* close the cursor and return */
close curs
return
Is This Answer Correct ? | 0 Yes | 0 No |
Can we use pl sql in mysql?
when a procedure /package is getting invalidated?
How to set up sql*plus output format in oracle?
What does t sql mean?
i need department wise top 2 employees salary.which logic i will use
how is exception handling handled in mysql? : Sql dba
how to create user in sql and how to set password for that?
What does seeding a database mean?
Can we join more than 2 tables in sql?
What is an index? What are the types of indexes? How many clustered indexes can be created on a table?
What are the two parts of a procedure ?
how to find the second highest salary from emp table?
211 Answers CIS, Cognizant, Cosmosoft, DAS, EDS, GreenTech, HOV Services, IBM, Infosys, National Institute of Science and Technology, Patni, Persistent, Polaris, TCS, Wipro, Yardi, Zensar,