| Sum of length of column data of all tables [message #561660] |
Tue, 24 July 2012 11:34  |
 |
sarma.shp
Messages: 108 Registered: February 2012
|
Senior Member |
|
|
Hi everybody, i want to add a column data of datatype number of all the tables at a time in a database..
i am trying with the all_tab_columns but i can get only the column info whether it is number or varchar2 or any other data type but i am unable to retrieve the column name and the sum of length of the data present in all the rows in that column...
can anyone help me?
|
|
|
|
|
|
| Re: Sum of length of column data of all tables [message #561662 is a reply to message #561660] |
Tue, 24 July 2012 11:39   |
 |
Littlefoot
Messages: 17256 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
OK, let's stay with a single user - Scott. Here are some information about its EMP table:SQL> l
1 select column_name, data_type, data_length, data_precision, data_scale
2 from user_Tab_columns
3* where table_name = 'EMP'
SQL> /
COLUMN_NAM DATA_TYPE DATA_LENGTH DATA_PRECISION DATA_SCALE
---------- ---------- ----------- -------------- ----------
EMPNO NUMBER 22 4 0
ENAME VARCHAR2 10
JOB VARCHAR2 9
MGR NUMBER 22 4 0
HIREDATE DATE 7
SAL NUMBER 22 7 2
COMM NUMBER 22 7 2
DEPTNO NUMBER 22 2 0
8 rows selected.
SQL>
This are EMP table's NUMBER columns and their contents:SQL> select empno, mgr, sal, comm, deptno from emp;
EMPNO MGR SAL COMM DEPTNO
---------- ---------- ---------- ---------- ----------
7369 7902 800 20
7499 7698 1600 300 30
7521 7698 1250 500 30
7566 7839 2975 20
7654 7698 1250 1400 30
7698 7839 2850 30
7782 7839 2450 10
7788 7566 3000 20
7839 5000 10
7844 7698 1500 0 30
7876 7788 1100 20
7900 7698 950 30
7902 7566 3000 20
7934 7782 1300 10
14 rows selected.
SQL>
So, what do you want to get as a result?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Sum of length of column data of all tables [message #561754 is a reply to message #561753] |
Wed, 25 July 2012 03:06   |
 |
sarma.shp
Messages: 108 Registered: February 2012
|
Senior Member |
|
|
ohk..... but i executed or typed the procedure the way i posted ...so i didnt thought of formatting the code. so pasted it as it is.!
and also can u pls say me how to edit the sql ( in linux)
in windows we can type ed and press enter and can correct the previously exec command and can save it and close it..
but here in linux how can i do it?.. how to save and close the editor?
[Updated on: Wed, 25 July 2012 03:08] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Sum of length of column data of all tables [message #561907 is a reply to message #561905] |
Thu, 26 July 2012 04:34   |
 |
sarma.shp
Messages: 108 Registered: February 2012
|
Senior Member |
|
|
declare
fhandle utl_file.file_type;
cursor c1 is
select owner, column_name, table_name
from all_tab_columns
where data_type in ('NUMBER', 'VARCHAR2')
and owner in ('SCOTT', 'FRANJO')
order by owner, table_name;
str varchar2(200);
l_sum_len number;
begin
fhandle := UTL_FILE.FOPEN('temp_test','Sfg2.txt','w');
utl_file.new_line (fhandle);
for cur_r in c1 loop
str := 'select sum(length(' ||
cur_r.column_name ||
')) from ' ||
cur_r.owner ||'.'||
cur_r.table_name;
execute immediate (str) into l_sum_len;
utl_file.put_line(cur_r.owner ||
cur_r.table_name ||
cur_r.column_name ||
l_sum_len
);
end loop;
UTL_FILE.FCLOSE(fhandle);
end;
/
this was the code am using....
and created a new dir and granted read ,write permissions to public and
when i execute the floowing statement , it is showing no value.
select value from v$parameter where name ='utl_file_dir;
[Updated on: Thu, 26 July 2012 04:36] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|