摘要:Oracle PL/SQL how to use Cursor
Oracle Cursor http://www.tutorialspoint.com/plsql/plsql_cursors.htm
1. Declaring the Cursor
CURSOR c_customers IS SELECT id, name, address FROM customers;
2.Opening the Cursor
OPEN c_customers;
3.Fetching the Cursor
FETCH c_customers INTO c_id, c_name, c_addr;
4.Closing the Cursor
CLOSE c_customers;
EXAMPLE :
DECLARE
c_id customers.id%type; c_name customers.name%type; c_addr customers.address%type; CURSOR c_customers is SELECT id, name, address FROM customers; BEGIN OPEN c_customers; LOOP FETCH c_customers into c_id, c_name, c_addr; EXIT WHEN c_customers%notfound; dbms_output.put_line(c_id || ' ' || c_name || ' ' || c_addr); END LOOP; CLOSE c_customers; END;
If dbms_output.put_line not printing in the sql development result
execute set serveroutput on in SQL development command