what is cursor procedure



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

Post New Answer

More SQL PLSQL Interview Questions

What are all ddl commands?

0 Answers  


What are stuff and replace function?

0 Answers  


What is sql profiler in oracle?

0 Answers  


Why truncate is faster than delete?

0 Answers  


package specification-3 procedures package body-4 procedures how can i write for other procedure in package body

2 Answers   Reliance,






Can we insert delete data in view?

0 Answers  


How do I get sql certification?

0 Answers  


What is varchar data type in sql?

0 Answers  


How does postgresql compare to "nosql"?

0 Answers  


What is a constraint?

0 Answers  


How can we solve sql error: ora-00904: invalid identifier?

0 Answers  


can we write stored function in out parameters? how to call through select statement? how to written more than one value plz give the exmple?

1 Answers  


Categories