Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Determining the defined maximum length of a VARCHAR field
> Michael Young wrote:
>
>> Is there an easy way to determine the defined length of a >> VARCHAR/VARCHAR2 field in Oracle SQL? I write a lot of interfaces >> that import data, and many times I'd like to simply truncate the >> incoming text data to the length of the existing varchar column in a >> table. I know I can query 'user_tab_columns', but it seems that there >> should be a built-in function that takes the table name and the >> varchar column name and returns the defined maximum length for the >> column.
If I have understood the OP correctly, it is this very size of the varchar2 he wanted to know.
declare
unknown_size table_name.column_name%TYPE;
long_str varchar2(100);
begin
long_str := 'akjf alkdj fkjkejflakjdfk ajkdf';
unknown_size := long_str;
end;
/
As he doesn't know if unknown_size is larger then long_str, he doesn't know if the programm bombs at unknown_size := long_str and should take some measures such as unknown_size:=substr(long_str,1,sizeof(unknown_size)) where sizeof would be the requested function.
Rene Nyffenegger
-- Projektleitung und Entwicklung in Oracle/C++/C# Projekten http://www.adp-gmbh.ch/cv.htmlReceived on Wed Mar 12 2003 - 17:58:32 CST
![]() |
![]() |