I’m having an error in stored Procedure , probably within IF

Asked

Viewed 235 times

1

To procedure must insert a client with at least 10 characters in name, Uf(Federative unit) with 2 characters and monthly reindeer with more than 500.00.

Follow the query:

DELIMITER $$ 
CREATE PROCEDURE sp_incluir_cliente(in xnome varchar(45), in 
xrenda_mensal decimal(10,2),in xuf varchar(2));
    BEGIN
        IF (len(xnome))>=10 THEN
            IF xrenda_mensal>=500.00 THEN
               IF (len(xuf)>=2 THEN
                   insert into cliente(nome,renda_mensal,uf) 
                       VALUES(xnome,xrenda_mensal,xuf);
               END IF;
            END IF;
        END IF;
END $$

Follows the response of phpmyadmin with reference to my mistakes:

#1064 - Você tem um erro de sintaxe no seu SQL próximo a ';
BEGIN
    IF (len(xnome))>=10 THEN
        IF xrenda_mensal>=500.00 THEN
            ' na linha 1

BS: I believe it’s something in IF however as I did not know how to solve I may be wrong.

1 answer

1


You have to inform which database you are using, because each system has its particularities.

This syntax is looking like Mysql, on account of DELIMITER, if that’s the problem BEGIN and the end of the Procedure parameter declaration has a ';'. Take it out.

DELIMITER $$ 
CREATE PROCEDURE sp_incluir_cliente(in xnome varchar(45), in 
xrenda_mensal decimal(10,2),in xuf varchar(2))
BEGIN
        IF (len(xnome))>=10 THEN
            IF xrenda_mensal>=500.00 THEN
               IF (len(xuf)>=2 THEN
                   insert into cliente(nome,renda_mensal,uf) 
                       VALUES(xnome,xrenda_mensal,xuf);
               END IF;
            END IF;
        END IF;
END $$
  • Not that the rpoblema no, put with the ';' and did not solve.

  • in question is with ';' CREATE PROCEDURE sp_incluir_cliente(in xnome varchar(45), in 
xrenda_mensal decimal(10,2),in xuf varchar(2));

  • @Gabrielsilva: I don’t know if you understand, but it’s without the point and comma

Browser other questions tagged

You are not signed in. Login or sign up in order to post.