---
title: "Curson"
author: "IT009"
date: "2011-07-06T16:46:52Z"
tags: []
categories: ["数据库"]
slug: "curson"
draft: false
lastmod: "2011-07-30T08:12:49Z"
id: 1117154
url: "https://it009.iteye.com/blog/1117154"
---

declare
cursor c_user is
select id,subscriberidentify,msisdn from t_pcc_subscriber;
c_user1 c_user%rowtype;

begin
     open c_user;
     loop
         fetch c_user into c_user1;
         if c_user%found then
            dbms_output.put_line(c_user1.subscriberidentify);
         end if;
         
         exit when c_user%NOTFOUND;
     end loop;
     close c_user;
     
end;



declare
type tmp_curson is ref cursor;
v_curson tmp_curson;
Shop_Name varchar2(50);
c_exp exception;
begin
     
     open v_curson for select Shop_Name from SHOP;
     loop
         fetch v_curson into Shop_Name;
               if v_curson%found then
                         dbms_output.put_line(Shop_Name);
                          update SHOP set Shop_Name = '9999888' where Shop_Id = 6;
                         SAVEPOINT SPT_ADD_SUBSCRIPTION;	
                        -- update SHOP set Shop_Name = '9999888' where Shop_Id = 6;
                         raise c_exp;
               end if;
         
         exit when v_curson%notfound;
     end loop;
     close v_curson;
     commit;
     
     exception
     when c_exp then
          dbms_output.put_line('c_exp...');
          ROLLBACK TO SAVEPOINT SPT_ADD_SUBSCRIPTION;
     when others then
          dbms_output.put_line(Sqlerrm);
              
end;