title: Unable to CREATE FUNCTION in MYSQL ERROR 1064 (42000)
body: <p>Hi I'm using MySQL to create a function:</p>
  
  <pre><code>CREATE FUNCTION INSERTGROUP(name VARCHAR(50))
  RETURNS INT
  NOT DETERMINISTIC
  BEGIN
  DECLARE 'idGroup' INT;
  
  IF (NOT EXISTS (SELECT groupID FROM groupsTable WHERE groupName = 'name'))
  THEN INSERT INTO groupsTable (groupName) VALUES ('name');
  
  SELECT groupID INTO 'idGroup' FROM groupsTable WHERE groupName='name';
  
  RETURN 'idGroup';
  END//
  </code></pre>
  
  <p>But I get this error when I try to create it:</p>
  
  <pre><code>ERROR 1064 (42000): 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
  ''idGroup' INT;
  
  IF (NOT EXISTS (SELECT groupID FROM serverGroupsTable WHERE gro' at line 5
  </code></pre>
  
  <p>I've been through forums and other questions similar to this one but I can not make it create the function.</p>
  
  <p>What I'm doing wrong? Is the syntax correct? Do I need to add something else?</p>
  
  <p>Ok this is what I've try:</p>
  
  <pre><code>CREATE FUNCTION INSERTGROUP(name VARCHAR(255))
  RETURNS INT
  NOT DETERMINISTIC
  BEGIN
  DECLARE idGroup INT;
  
  IF (NOT EXISTS (SELECT groupID FROM groupsTable WHERE groupName = name))
  THEN INSERT INTO groupsTable (groupName) VALUES (name);
  
  SELECT groupID INTO idGroup FROM groupsTable WHERE groupName=name;
  
  RETURN idGroup;
  END//
  </code></pre>
  
  <p>and</p>
  
  <pre><code>CREATE FUNCTION INSERTGROUP(name VARCHAR(255))
  RETURNS INT
  NOT DETERMINISTIC
  BEGIN
  DECLARE idGroup INT;
  
  IF (NOT EXISTS (SELECT groupID FROM groupsTable WHERE groupName = 'name'))
  THEN INSERT INTO groupsTable (groupName) VALUES ('name');
  
  SELECT groupID INTO idGroup FROM groupsTable WHERE groupName='name';
  
  RETURN idGroup;
  END//
  </code></pre>
  
  <p>and for the last two I got this error:</p>
  
  <pre><code>ERROR 1064 (42000): 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 13
  </code></pre>
  
  <p>Similar to the one above</p>
  
  <p>Also I do <code>DELIMITER //</code> to change it from <code>;</code></p>