Using table created in example above, this is what I get when I run the code...

SQL> set serveroutput on
SQL> /
SELECT MAX(DEPTNO) FROM DEPT
SELECT MAX(EMPNO) FROM EMP
SELECT MAX(COL1) FROM TEST1
SELECT MAX(COL2) FROM TEST1


PL/SQL procedure successfully completed.

SQL>

There are two loops in the procedure, one to step through the PK constraints, and using the constraint name found we then loop through all the columns in the constraint generating the SQL he wants.

JR