1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
| SQL> DECLARE
2 Modal varchar2(1000);
3 l_cursor sys_refcursor;
4 l_cnt number;
5 l_lacol varchar2(30);
6 cursor curs IS
7 SELECT column_name col_, table_name tab_
8 FROM user_tab_columns
9 WHERE table_name = 'EMP';
10
11 BEGIN
12 FOR c IN curs LOOP
13 Modal:='select count(*) as cnt, '|| c.col_ || ' as lacol from '|| c.tab_ ||' group by ' ||c.col_;
14 dbms_output.put_line (rpad(c.col_,30) || ' ' || rpad('cnt',7));
15 dbms_output.put_line (rpad('-',30,'-') || ' ' || rpad('-',7,'-'));
16 open l_cursor for modal;
17 loop fetch l_cursor into l_cnt,l_lacol;
18 exit when l_cursor%notfound;
19 dbms_output.put_line (rpad(coalesce(l_lacol,'__NULL__'),30) || ' ' || lpad(l_cnt,7));
20 end loop;
21 dbms_output.put_line (chr(10));
22 dbms_output.put_line (rpad('#',38,'#'));
23 dbms_output.put_line (chr(10));
24 END LOOP;
25 END;
26 /
EMPNO cnt
------------------------------ -------
7782 1
7839 1
7844 1
7698 1
7521 1
7902 1
7566 1
7654 1
7788 1
7934 1
7499 1
7876 1
7369 1
7900 1
######################################
ENAME cnt
------------------------------ -------
ALLEN 1
JONES 1
FORD 1
CLARK 1
MILLER 1
SMITH 1
WARD 1
MARTIN 1
SCOTT 1
TURNER 1
ADAMS 1
BLAKE 1
KING 1
JAMES 1
######################################
JOB cnt
------------------------------ -------
CLERK 4
SALESMAN 4
PRESIDENT 1
MANAGER 3
ANALYST 2
######################################
MGR cnt
------------------------------ -------
7839 3
__NULL__ 1
7782 1
7698 5
7902 1
7566 2
7788 1
######################################
HIREDATE cnt
------------------------------ -------
17/11/81 1
03/12/81 2
23/01/82 1
22/02/81 1
12/01/83 1
17/12/80 1
09/06/81 1
09/12/82 1
20/02/81 1
02/04/81 1
01/05/81 1
08/09/81 1
28/09/81 1
######################################
SAL cnt
------------------------------ -------
2450 1
5000 1
1300 1
1250 2
2850 1
2975 1
1100 1
3000 2
800 1
1600 1
1500 1
950 1
######################################
COMM cnt
------------------------------ -------
__NULL__ 10
1400 1
500 1
300 1
0 1
######################################
DEPTNO cnt
------------------------------ -------
30 6
20 5
10 3
######################################
PL/SQL procedure successfully completed.
SQL> |