Is it possible to get all columns (varchar2, char, nvarchar2), where the data is as long (or nearly as long - 2 characters less) than the allowed maximum size of the column in an Oracle Database?
With the following statement, I get the maximum allowed size for each column:
select table_name, column_name, data_type, data_length
from user_tab_columns
where data_type in ('VARCHAR2', 'CHAR', 'NVARCHAR2')
order by data_type;
Now I want to find every column where max(length(column))+2 >= data_length
For example:
The output of my statement is following:
TableA | ColumnA | VARCHAR2 | 30
TableA | ColumnB | VARCHAR2 | 30
TableB | ColumnA | VARCHAR2 | 50
TableB | ColumnB | VARCHAR2 | 50
Now I have to run
SELECT MAX(LENGTH(ColumnA)) FROM TableA;
SELECT MAX(LENGTH(ColumnB)) FROM TableA;
SELECT MAX(LENGTH(ColumnA)) FROM TableB;
SELECT MAX(LENGTH(ColumnB)) FROM TableB;
with following results:
- 20 (is not important, because maximum allowed length is 30)
- 30 (is important, because maximum allowed length is 30)
- 30 (is not important, because maximum allowed length is 50)
- 50 (is important, because maximum allowed length is 50)
Is this possible to find all of them with a script or a statement?