--簡單循環(huán)
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循環(huán)
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;
--游標(biāo)FOR循環(huán)
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;