This Is A FineDay

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  93 随笔 :: 0 文章 :: 69 评论 :: 0 Trackbacks

--简单循环
SET SERVEROUTPUT ON
DECLARE
       v_t_customer t_customer%ROWTYPE;
       v_customer_id t_customer.customer_id%TYPE;
       v_customer_name t_customer.customer_name%TYPE;
       CURSOR c_t_customer IS
        --select customer_id,customer_name from t_customer where rownum <= 10;
        select * from t_customer where rownum <= 10;
BEGIN
     OPEN c_t_customer;
       LOOP
         --fetch c_t_customer into v_customer_id,v_customer_name;
         FETCH c_t_customer INTO v_t_customer;
        
         dbms_output.put_line('customer_id :'||v_t_customer.customer_id||' customer_name :'||v_t_customer.customer_name);
         EXIT WHEN c_t_customer%NOTFOUND;
       END LOOP;
     CLOSE c_t_customer;
EXCEPTION
         WHEN OTHERS THEN
         ROLLBACK; 
         DBMS_OUTPUT.put_line('exception'); 
END;
     
--WHILE循环
SET SERVEROUTPUT ON
DECLARE
       v_t_customer t_customer%ROWTYPE;
       v_customer_id t_customer.customer_id%TYPE;
       v_customer_name t_customer.customer_name%TYPE;
       CURSOR c_t_customer IS
        --select customer_id,customer_name from t_customer where rownum <= 10;
        select * from t_customer where rownum <= 10;
BEGIN
     OPEN c_t_customer;
       --fetch c_t_customer into v_customer_id,v_customer_name;
       FETCH c_t_customer INTO v_t_customer;
       WHILE c_t_customer%FOUND LOOP
         --fetch c_t_customer into v_customer_id,v_customer_name;
         FETCH c_t_customer INTO v_t_customer;
         dbms_output.put_line('customer_id :'||v_t_customer.customer_id||' customer_name :'||v_t_customer.customer_name);
       END LOOP;
     CLOSE c_t_customer;
EXCEPTION
         WHEN OTHERS THEN
         ROLLBACK; 
         DBMS_OUTPUT.put_line('exception'); 
END;

--游标FOR循环
SET SERVEROUTPUT ON
DECLARE
       v_t_customer t_customer%ROWTYPE;
       v_customer_id t_customer.customer_id%TYPE;
       v_customer_name t_customer.customer_name%TYPE;
       CURSOR c_t_customer IS
        --select customer_id,customer_name from t_customer where rownum <= 10;
        select * from t_customer where rownum <= 10;
BEGIN
       FOR v_t_customer IN c_t_customer LOOP
         dbms_output.put_line('customer_id :'||v_t_customer.customer_id||' customer_name :'||v_t_customer.customer_name);
       END LOOP;
EXCEPTION
         WHEN OTHERS THEN
         ROLLBACK; 
         DBMS_OUTPUT.put_line('exception'); 
END;

posted on 2007-03-09 15:30 Peter Pan 阅读(320) 评论(0)  编辑  收藏 所属分类: DB

只有注册用户登录后才能发表评论。


网站导航: