> Home > Scripts > Oracle >

Example of PL/SQL loop

This script should be run from SQL*plus prompt. This can also be placed in a file and ran from the SQL*plus prompt

 

--

-- Created by Jeffery J. Jimes

-- Date 08/22/2001

-- Description: This is a example of a PL/SQL loop example.

-- 

 

DECLARE
-- variables
v_table_name user_tables.table_name%TYPE;

-- cursors
CURSOR cur_table_names IS
SELECT table_name
FROM user_tables;

BEGIN

    -- open cursor
    OPEN cur_table_names;

    LOOP

        FETCH cur_table_names
        INTO v_table_name;


        SELECT table_name 

        FROM user_table 

        WHERE table_name = v_table_name;

        EXIT WHEN cur_table_names%NOTFOUND; 
    END LOOP;

    -- close cursor
    CLOSE cur_table_names;
END;

 

/