Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Determining Varchar Maximum Length
> Hi,
>
> I am writing a server in Java that connects to an Oracle database. I have a
> table called USERS. A column in USERS is called ID. ID has type
> VARCHAR(10). My problem is how do I write code that gets the size 10.
> Could it be done in SQL, PL/SQL, or some method from Oracle JDBC driver?
> Thanks a lot.
>
> Sam Lai
Sam,
you could try to query user_tab_columns;
set feedback off
create table l (
a varchar2(10), b varchar2(20), c varchar2(30),
create or replace
function get_length_varchar2
(p_table_name in Varchar2, p_column_name in Varchar2) return numberis
select
data_type, data_length into v_data_type, v_data_length from user_tab_columns where table_name = p_table_name and column_name= p_column_name; if v_data_type <> 'VARCHAR2' then return -1;
return v_data_length;
end;
/
select get_length_varchar2('L','A') "Length A" from dual; select get_length_varchar2('L','B') "Length B" from dual; select get_length_varchar2('L','C') "Length C" from dual; select get_length_varchar2('L','D') "Length D" from dual;
drop table l;
drop function get_length_varchar2;
Rene
-- no sig todayReceived on Sun Jan 19 2003 - 06:05:40 CST
![]() |
![]() |