zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    Ocaml入门(3)
    Delphi数组成员丢失
    Delphi合并2个动态数组
    Delphi用指针读取数组某个元素
    Delphi函数返回数组之TList函数返回
    Delphi函数返回数组之使用TList参数
    Delphi让函数返回数组
    Delphi双向链表
    Delphi指针与string
    Delphi函数指针,用于加载DLL
  • 原文地址:https://www.cnblogs.com/cooper-73/p/15046370.html
Copyright © 2011-2022 走看看