Find the length of the longest row in a column in oracle

后端 未结 9 1552
野趣味
野趣味 2020-12-16 14:19

Does anybody know if there is a way to find what the length of the longest row in a column in Oracle?

Basically I need to get the length of the longest row and then

9条回答
  •  盖世英雄少女心
    2020-12-16 14:30

    w/o function:

    select 
      rpad(tbl.column_name, length_info.max_length+1, ' ') as target_string
    from 
      table_name tbl,
      (
        select max(length(column_name)) max_length 
        from my_table
      ) 
        length_info
    

    with your function:

    select 
      rpad(tbl.column_name, MaxLengthFunc + 1, ' ') as target_string
    from 
      my_table tbl
    

    declare your function as determinictic for better performance:

    create or replace function MaxLengthFunc 
    return number  
    deterministic
    as
      vMaxLen number;
    begin
    
      select max(length(column_name)) 
      into vMaxLen
      from table_name;
    
      return vMaxLen;
    
    end;
    

提交回复
热议问题