Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is cursor procedure

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a table contain multiple foreign key’s?

950


What is pl sql variable?

939


when MSQL8.0 is in market

2018


Can we perform dml on view?

977


What is dense_rank in sql?

918


Which data dictionary views have the information on the triggers that are available in the database?

1182


What is rank () in sql?

887


how to create a new table by selecting rows from another table in mysql? : Sql dba

1012


Is there a pl/sql pragma similar to deterministic, but for the scope of one single sql select?

971


How to write a single statement that concatenates the words ?hello? And ?world? And assign it in a variable named greeting?

1038


Can we commit inside a trigger?

945


What if we write return in procedure?

1337


What are the topics in pl sql?

933


How does postgresql compare to oracle/db2/ms sql server/informix?

984


How can you fetch first 5 characters of the string?

948