Is there a function to repeat a character ? [message #316742] |
Mon, 28 April 2008 03:11  |
walter01
Messages: 28 Registered: April 2008
|
Junior Member |
|
|
Is there a function that repeats a character a given number of times and returns this as a character string ?
For instance to check if a VARCHAR2(30) field contains only spaces :if table.column = some_build_in_function(30, ' ')
...
end if;
is the same as ...
if table.column = ' '
...
end if;
thanks,
Walter
|
|
|
|
|
Re: Is there a function to repeat a character ? [message #316771 is a reply to message #316743] |
Mon, 28 April 2008 05:06   |
dr.s.raghunathan
Messages: 540 Registered: February 2008
|
Senior Member |
|
|
hi
even if you use lpad, rpad for '-', ' ' the multiple characters
are getting shrinked and displays as single character only in apex pages.
For example 'raghu--------' will display as 'raghu-'. This doubt has been raised in Applection express MOD still it is unanswered..
yours
dr.s.raghunathan
|
|
|
|
|
|
|
|
|
|
|
Re: Is there a function to repeat a character ? [message #317198 is a reply to message #316742] |
Tue, 29 April 2008 21:32   |
harrysmall3
Messages: 109 Registered: April 2008 Location: Massachusetts
|
Senior Member |
|
|
Hi Walter, lemme see if i interpret your first message correctly as i just had to do some painstaking string work on a project (like take string1 and string2 and see if any n amount of chars is in string2, or concatonate string1,2,3,4 - stip double spaces to single then take the first letter after each space and build an acronym to check against another field -
a lot of fuzzy name comparissons on insurance claims.
Anyway if you wanted a generic function to accept a string and see if it is all spaces (or any character for that matter)
you could have something like (im typing this off the top of my head, pls excuse fat fingering on syntax!)
create or replace function isSpaces(text1 in varchar2 return number)
deterministic -- always a performance help when true
IS
lvText varchar2(255) := null;
BEGIN
lvText := text1;
while instr(lvText,' ') > 0 loop
replace lvText(' ',' ');
end loop;
if lvtext := ' ' then
return 1; -- 'yes'
end if;
return 0; -- 'no'
end isSpaces;
then anywhere you can do stuff like
select count(*) as space_rec_count from table_A where
isSpaces(table_A.some_string_field) > 0;
the function isSpaces could be turned generic if you pass in
the character(S) you are checking for and just reduce via replace.
not sure if thats what you were really gaging towards but
thought i'd share because i have found over time that building one's own little utility collection of generic string functions
in the long run can remove having to retype long
instr() substr() nested funcs to form algorithms of similar nature.
best wishes
harry
|
|
|
|
|
|