0

I try to update a table inside a procedure.

Here I want to uppercase first letter on "apellido" and "nombre" if ID of user existe

I'm using PhpmyAdmin with MySQL

DELIMITER  $$
DROP PROCEDURE IF EXISTS  usuarioExiste  $$
CREATE PROCEDURE  usuarioExiste (IN id_usuario_busca INT, OUT existe BOOLEAN)

SET existe = (SELECT COUNT(id_usuario) FROM usuario WHERE id_usuario = id_usuario_busca);
IF existe > 0 THEN
    BEGIN   
      UPDATE usuario
      SET nombre=Concat(UPPER(LEFT(nombre,1)),LOWER(SUBSTRING(nombre,2))),
      apellido =Concat(UPPER(LEFT(apellido,1)),LOWER(SUBSTRING(apellido,2)))
      WHERE id_usuario = id_usuario_busca; 
    END;
END IF;
END $$
DELIMITER ;

But currently I got this error:

Syntax error near ' 'IF existe > 0 THEN BEGIN
UPDATE usuario SET nombre=Concat(UP...'

Milirium
  • 31
  • 1
  • 4
  • apellido = **,** Concat, remove the comma! – jarlh Jan 12 '22 at 11:26
  • 2
    PL/SQL means *Oracle* (it is Oracle's procedural extension to SQL). Code you posted is **not** Oracle; what is it? PostgreSQL? If so, you should've used the **plpgsql** tag instead. – Littlefoot Jan 12 '22 at 11:26
  • I'm using PhpmyAdmin with MySQL – Milirium Jan 12 '22 at 11:34
  • Something is completely messed up here... Your text says something about PL/SQL, which is Oracle's procedural extension. The tag says PL/pgSQL, which is Postgres' procedural extension. Then you wrote you use MySQL, which has yet another procedural extension... None of them are interchangeable. You should first sort out what you really have and use the matching language for that. – sticky bit Jan 12 '22 at 11:43
  • 1
    The procedure code itself is correct. https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=f3e0008621b78fabe15371746e9030ce Investigate PhpmyAdmin documentation, study "How to create stored procedures". – Akina Jan 12 '22 at 12:24
  • Try reading this- https://stackoverflow.com/questions/17481890/how-to-write-a-stored-procedure-in-phpmyadmin – user1191247 Jan 12 '22 at 12:32

0 Answers0