Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread What's the longest string
Sun, Oct 31 2010 3:42 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

For purposes of setting report columns widths I want to find out the longest piece of text in each column. No problem for simple fields but does anyone have a suggestion for finding the longest string in a CLOB. I don't want the overall length of all the text in the field but the longest string eg

CLOB is
One
Two
Three
Four
Five
Six
Seven
Eight
Nine
Ten

The answer should be 5

Roy Lambert
Mon, Nov 1 2010 6:43 AMPermanent Link

John Hay

Roy
> For purposes of setting report columns widths I want to find out the
longest piece of text in each column. No problem for simple fields but does
anyone have a suggestion for finding the longest string in a CLOB. I don't
want the overall length of all the text in the field but the longest string
eg
>
> CLOB is
> One
> Two
> Three
> Four
> Five
> Six
> Seven
> Eight
> Nine
> Ten
>
> The answer should be 5

How about a function like

CREATE FUNCTION "LongestString" (IN "InString" CLOB COLLATE ANSI)
RETURNS INTEGER
BEGIN
DECLARE i,highest INTEGER;
DECLARE st CLOB;

SET st = InString;
SET highest = 0;
WHILE pos(#13+#10,st) > 0 DO
 SET i = pos(#13+#10,st)-1;
 IF highest < i THEN
   SET highest = i;
 END IF;
 SET st = RIGHT(st,LENGTH(st)-POS(#13+#10,st)-1);
END WHILE;
SET i = LENGTH(st);
IF highest < i THEN
 SET highest = i;
END IF;
RETURN highest;
END

John

Mon, Nov 1 2010 7:23 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

John


Nice and works well.

Roy Lambert
Mon, Nov 1 2010 7:51 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

John,

You're like an SQL robot - plug in your request and out pops the SQL. Wink

Thanks,

--
Tim Young
Elevate Software
www.elevatesoft.com
Image