oracle整库统计库表各个字段数据最大长度--存储过程

2021/7/23 2:07:30

本文主要是介绍oracle整库统计库表各个字段数据最大长度--存储过程,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 1 CREATE OR REPLACE PROCEDURE TABLES_COL_MAX AS
 2   COUNT_SQL    VARCHAR2(2000);
 3   P_TABLE_NAME VARCHAR2(2000);
 4   P_COL_NAME   VARCHAR2(2000);
 5   P_COL_TYPE   VARCHAR2(2000);
 6   P_DATA_LEN   VARCHAR2(2000);
 7   EXCEPT_SQL VARCHAR2(2000);
 8 BEGIN
 9   EXECUTE IMMEDIATE 'DROP TABLE T_ROWS_MAX';
10   EXECUTE IMMEDIATE 'CREATE TABLE T_ROWS_MAX (TABLE_NAME varchar2(200)  ,COL_NAME varchar2(200),COL_TYPE varchar2(50), LENMAX number)';
11   FOR CUR IN (select uc.TABLE_NAME, uc.COLUMN_NAME, uc.data_type,uc.data_length
12                 from user_tab_columns uc) LOOP
13     P_TABLE_NAME := CUR.TABLE_NAME;
14     P_COL_NAME   := CUR.COLUMN_NAME;
15     P_COL_TYPE   := CUR.data_type;
16     P_DATA_LEN   := CUR.data_length;
17     IF P_COL_TYPE <>'BLOB' OR P_COL_TYPE <>'CLOB' THEN
18       BEGIN
19         COUNT_SQL    := 'insert into  T_ROWS_MAX(TABLE_NAME,COL_NAME,COL_TYPE,LENMAX)  SELECT ''' ||
20                     P_TABLE_NAME || '''AS  TABLE_NAME , ''' || P_COL_NAME ||
21                     '''AS  COL_NAME, ''' || P_COL_TYPE ||
22                     '''AS  COL_TYPE, MAX(LENGTH('||P_COL_NAME||'
23                     )) AS LENMAX  FROM ' || P_TABLE_NAME;
24         EXECUTE IMMEDIATE COUNT_SQL;
25         COMMIT;
26       EXCEPTION
27         WHEN OTHERS THEN
28         EXCEPT_SQL    := 'insert into  T_ROWS_MAX(TABLE_NAME,COL_NAME,COL_TYPE,LENMAX)  SELECT ''' ||
29                     P_TABLE_NAME || '''AS  TABLE_NAME , ''' || P_COL_NAME ||
30                     '''AS  COL_NAME, ''' || P_COL_TYPE ||
31                     '''AS  COL_TYPE, '|| P_DATA_LEN ||'  AS LENMAX  FROM ' || P_TABLE_NAME;
32 
33         EXECUTE IMMEDIATE EXCEPT_SQL;
34         COMMIT;
35       END;
36      END IF;
37   END LOOP;
38 
39 END TABLES_COL_MAX;

 



这篇关于oracle整库统计库表各个字段数据最大长度--存储过程的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程