Sorry Mike - I was having a hard day ;-)
I may be wrong (seems common at the moment) but I don't think that
your example will work as if you had 10 lines, each with 79 characters
and a carriage return (Char(13) then your method would calculate that
you need ((10x79)+(10*80)/80)= 20, whereas it actually requires 10
lines.
I have actually finally managed to come up with a solution now though
- many thanks for all of your help.
CREATE OR REPLACE FUNCTION CountLines
(TextString in varchar2, ColumnWidth in integer)
RETURN NUMBER IS tmpVar NUMBER;
position integer;
linecount integer;
pos_var integer;
pos_curr integer;
BEGIN
tmpVar := 0;
position := 1;
linecount := 1;
pos_curr := 0;
--
WHILE position <= LENGTH(TextString)
LOOP
pos_curr := pos_curr + 1;
pos_var := ASCII(SUBSTR(TextString, position, 1)) ;
IF (pos_var = 9)
THEN
pos_curr := pos_curr + 5;
END IF ;
IF (pos_var = 13
--OR pos_var = 10
OR pos_curr >= ColumnWidth)
THEN
pos_curr := 0;
linecount := linecount + 1;
END IF;
position := position + 1;
end loop;
RETURN linecount;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END CountLines;
/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Oracle PL/SQL" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Oracle-PLSQL?hl=en
-~----------~----~----~----~------~----~------~--~---