|
-
procedure
Here is an example procedure to generate SQL to find the maximum value for every column in all the primary keys in your current schema. If you want this for every schema replace the references to USER_ views with DBA_ . In that case you will probably want to filter out SYS owned tables etc.
So you could SET SERVEROUTPUT ON, set a spool file, then run the below procedure. Edit the spool file to get rid of the junk lines then execute it.
JR
DECLARE
stmt varchar2(200);
c1_rec user_constraints%ROWTYPE;
c2_rec user_cons_columns%ROWTYPE;
BEGIN
FOR c1_rec IN
(select * from user_constraints where constraint_type = 'P')
LOOP
-- Since a primary key can be composed of
-- multiple columns, build SQL for each one
FOR c2_rec IN
(SELECT COLUMN_NAME FROM USER_CONS_COLUMNS
WHERE CONSTRAINT_NAME = c1_rec.constraint_name
ORDER BY POSITION)
LOOP
-- Now build SQL to get max value for each column and output
stmt := 'SELECT MAX(' || c2_rec.column_name || ') FROM ' || c1_rec.table_name;
dbms_output.put_line(stmt);
END LOOP;
END LOOP;
END;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|