0
drop function if exists Proper;
create function Proper
(
txt varchar(100)
)
returns varchar(100)
begin
  declare pos integer;
  declare len integer;
  declare result varchar(100);

  if (txt is null) then
    set result = null;
  else
    set result = '';
  end if;
  set pos = 0;

  while (char_length(txt) > char_length(result)) do
    set pos = char_length(result)+1;

    -- check for 'Mc'
    set len = position('MC' in upper(substring(txt from pos for 2)));
    if (len > 0) then
      if (substring(txt from pos+2 for 1) in (chr(32),chr(39),chr(45))) then
        set len = 2;
      end if;
    end if;

    -- check for quote
    if (len = 0) then
      set len = position(chr(39) in substring(txt from pos+1 for 1));
      if (len > 0) then
        set len = 1;
      end if;
    end if;

    -- check for hyphen
    if (len = 0) then
      set len = position(chr(45) in substring(txt from pos+1));
    end if;

    -- check for space
    if ( len = 0) then
      set len = position(chr(32) in substring(txt from pos+1));
    end if;

    -- no special characters
    if (len = 0) then
      set len = char_length(substring(txt from pos+1));
    end if;

    set result =
      result||
      upper(substring(txt from pos for 1))||
      lower(substring(txt from pos+1 for len));
  end while;

  return result;
end;
Category: 
SQL Functions & Procedures
Current Version: 
1.00
Supported Products: 
NexusDB V2
NexusDB V3
Home