Sample Cursor in Oracle Sql

Sample PL/SQL Programming

SET SERVEROUTPUT ON;

BEGIN
   dbms_output.put_line  (user || ' Tables in the database:');
   FOR t IN (SELECT table_name FROM user_tables)
   LOOP
      dbms_output.put_line(t.table_name);
   END LOOP;
END;

Sample Cursor Example 

DECLARE
    CURSOR emp_cursor IS
    SELECT
        first_name
    FROM
        emp;

    cur_first_name emp.first_name%TYPE;
BEGIN
    OPEN emp_cursor;
    LOOP
        FETCH emp_cursor INTO cur_first_name;
        IF emp_cursor%notfound THEN
            EXIT;
        END IF;
        dbms_output.put_line('Emp First Name :' || cur_first_name);
    END LOOP;

    dbms_output.put_line(' Total Count ' || emp_cursor%rowcount);
    CLOSE emp_cursor;
END;

Comments

Popular posts from this blog