If I remember something from Sybase right, COL_LENGTH gets the
length of table column ?
SQL> create or replace function get_col_length (
2 tabname varchar2,
3 colname varchar2
4 )
5 return number
6 is
7 ln number;
8 begin
9 begin
10 select data_length into ln from user_tab_cols where table_name = upper(tabname)
11 and column_name = upper(colname);
12 exception
13 when no_data_found then
14 ln := 0;
15 when others then
16 raise;
17 end;
18 return ln;
19 end;
20 /
Function created.
Elapsed: 00:00:00.01
SQL> var len number;
SQL> exec :len := get_col_length('emp','ename');
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.00
SQL> print len
LEN
----------
10
Or you can use dbms_sql package:
SQL> create or replace function get_col_length2 (
2 tabname varchar2,
3 colname varchar2
4 )
5 return number
6 is
7 c integer;
8 rec_tab dbms_sql.desc_tab;
9 col_cnt integer;
10 begin
11 c := dbms_sql.open_cursor;
12 dbms_sql.parse(c,'select ' || colname || ' from ' || tabname, dbms_sql.native);
13 dbms_sql.describe_columns(c, col_cnt, rec_tab);
14 dbms_sql.close_cursor(c);
15 return rec_tab(1).col_max_len;
16 end;
17 /
Function created.
Elapsed: 00:00:00.01
SQL> exec :len := get_col_length2('emp','ename');
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.00
SQL> print len
LEN
----------
10
Rgds.