PL/SQL Fetch

Oracle PL/SQL Fetch Example

DECLARE
	v_name customers.customer_name%TYPE; 
	v_amount contracts.amount%TYPE; 
	CURSOR c IS 
		SELECT cust.customer_name, ctr.amount 
		FROM customers cust, contracts ctr
		WHERE ctr.customer_id = cust.customer_id
		AND ctr.contract_id = 4003;
BEGIN
	OPEN c; 
	LOOP
		FETCH c INTO v_name, v_amount; 
		EXIT WHEN c%NOTFOUND;
		DBMS_OUTPUT.PUT_LINE ('Customer: '||v_name||' '||v_amount||'');
	END LOOP;
	CLOSE c;
END;