Re: Fault with initcap
От | Shaozhong SHI |
---|---|
Тема | Re: Fault with initcap |
Дата | |
Msg-id | CA+i5JwYeE4cKg7baz1UP9vUXX+n6UWOw98DLgVRDuB_szpN45w@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Fault with initcap (Metin Ulusinan <metin.ulusinan@ssicilian.net>) |
Ответы |
Re: Fault with initcap
|
Список | pgsql-sql |
On Wed, 13 Oct 2021 at 10:39, Metin Ulusinan <metin.ulusinan@ssicilian.net> wrote:
Hi,Yes, this can be adaptable, and i did simple version of this.It just split text words with find spaces, capitalise eachpieces(word) and merge together again.This is a quick and simple work. You can develop over it about your needs.Try that and tell us about result.CREATE OR REPLACE FUNCTION initcap2(text)
RETURNS text
LANGUAGE plpgsql
AS $function$
DECLARE
sentence TEXT := '';
word_array TEXT[];
word TEXT;
word_out TEXT;
BEGIN
sentence := $1;
IF sentence is NULL THEN
RETURN NULL;
END IF;
word_array := regexp_split_to_array($1, E'\\s+');
FOREACH word IN ARRAY word_array
LOOP
word_out := upper(left(word, 1)) || lower(substring(word, 2));
sentence := regexp_replace(sentence, word, word_out);
END LOOP;
RETURN trim(sentence);
END;
$function$
;Hello, Metin,
See the following testing response.
SQL state: 2201B
Regards,
David
В списке pgsql-sql по дате отправления: