Tuesday, September 28, 2010

Query columns used by views

this SQL block will tell you all the columns being used by a view.

SET serveroutput ON
DECLARE
-- local variables, create a cursor for the records
CURSOR c1
IS
SELECT text,view_name FROM dba_views WHERE owner = &&OWNER1;
CURSOR c2
IS
SELECT table_name,
column_name
FROM dba_tab_columns
WHERE owner =
&&OWNER1
ORDER BY 1,2;
BEGIN
DBMS_OUTPUT.ENABLE(1000000);
FOR r2 IN c2
LOOP
FOR r1 IN c1
LOOP
IF (instr(lower(r1.text),lower(r2.column_name)) > 0) THEN
dbms_output.put_line(r1.view_name || ',' ||r2.column_name ||','||r2.table_name);
dBMS_OUTPUT.NEW_LINE;
END IF;
END LOOP;
END LOOP;
END;

No comments: