55.2 GET_INITIALS Function

Returns the initials of the words in a string.

Words are separated by spaces or other special characters such as:

  • commas (,)
  • dashes (-)
  • quotes (')

If the input only has one word, returns the first characters of that word.

Syntax

APEX_STRING.GET_INITIALS (
   p_str IN VARCHAR2,
   p_cnt IN PLS_INTEGER DEFAULT 2 )
   RETURN VARCHAR2

Parameters

Parameters Description
p_string The input string.
p_cnt The number (N) of letter initials to get from the first number (N) of words. Default 2. Allowed values are 1 to 255.

Example

The following example gets initials from "John Doe".

BEGIN
  sys.dbms_output.put_line(apex_string.get_initials('John Doe'));   
END;

Output:
-> JD

Example 2

Gets the first three initials from "Andres Homero Lozano Garza".

BEGIN
  sys.dbms_output.put_line(apex_string.get_initials(p_str => 'Andres Homero Lozano Garza', p_cnt => 3));
END;

Output
-> AHL

Example 3

Gets the first three initials from "JBHiFi".

BEGIN
  sys.dbms_output.put_line(get_initials(p_str => 'JBHiFi', p_cnt => 3));
END;

Output:
-> JBH