title: Converting all text in a column to Camel Case in MySql
body: <p>I was searching for a way to convert all the text which I have in a database to Camel Case / Proper Case</p>
  
  <p>i.e. from <code>CAMEL HAS LEGS</code> to <code>Camel Has Legs</code></p>
  
  <p>I found an <a href="https://stackoverflow.com/a/32830244/4050261">answer here</a>, which asks to create a function (below) and then use the function to convert the text.</p>
  
  <p>I am using MySQL Version: <code>5.6.32-78.1</code> on a shared hosting server. When I execute the below function, I get error </p>
  
  <pre><code>#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 
  </code></pre>
  
  <p>How do I rectify this error? I am very new to MySQL</p>
  
  <pre><code>CREATE FUNCTION `proper_case`(str varchar(128)) RETURNS varchar(128)
  BEGIN
  DECLARE n, pos INT DEFAULT 1;
  DECLARE sub, proper VARCHAR(128) DEFAULT '';
  
  if length(trim(str)) &gt; 0 then
      WHILE pos &gt; 0 DO
          set pos = locate(' ',trim(str),n);
          if pos = 0 then
              set sub = lower(trim(substr(trim(str),n)));
          else
              set sub = lower(trim(substr(trim(str),n,pos-n)));
          end if;
  
          set proper = concat_ws(' ', proper, concat(upper(left(sub,1)),substr(sub,2)));
          set n = pos + 1;
      END WHILE;
  end if;
  
  RETURN trim(proper);
  END
  </code></pre>