0

I'm trying to create an stored procedure, but it always gives me an error

I've tried changing the symbols in the Delimiter, even removing the Delimiter, but nothing seems to work

DELIMITER //
CREATE PROCEDURE`check_values`(IN Autoridad, IN TipoVehiculo)
BEGIN
    IF((Autoridad <> 'Transito') OR (Autoridad <> 'Fiscalia')  OR (Autoridad <> 'Pol_Car') OR (Autoridad <> 'Juzgado')) THEN
        SIGNAL SQLSTATE '45000'
            SET MESSAGE_TEXT = 'Autoridad no valida';
    END IF;
    IF((TipoVehiculo <> 'Automovil') OR (TipoVehiculo <> 'Bicicleta') OR (TipoVehiculo <> 'Bus') OR (TipoVehiculo <> 'Buseta') OR (TipoVehiculo <> 'Camion') OR (TipoVehiculo <> 'Camioneta') OR (TipoVehiculo <> 'Ciclomotor') OR (TipoVehiculo <> 'Furgoneta')OR (TipoVehiculo <> 'Moto') OR (TipoVehiculo <> 'Motocarro') OR (TipoVehiculo <> 'Motocultor') OR (TipoVehiculo <> 'Tractocamion') OR (TipoVehiculo <> 'Tractocarro') OR (TipoVehiculo <> 'Trolebus') OR (TipoVehiculo <> 'Volqueta')) THEN
        SIGNAL SQLSTATE '45000'
            SET MESSAGE_TEXT = 'Tipo de vehiculo no valido';
    END IF;  
END;//
DELIMITER;

It returns an error in line 1: "You have an error in your SQL syntax; it seems the error is around: 'DELIMITER / / CREATE PROCEDURE check_values(IN Autoridad, IN TipoVehiculo) BEG' at line 1"

Draken
  • 1
  • 1

1 Answers1

0

"DELIMITER" is a client directive rather than a command the client passes to the server. This question indicates the error you are seeing may be caused by using a client that doesn't recognize "DELIMITER".

In addition, the next syntax error MySQL will show is that the arguments need a variable type:

CREATE PROCEDURE 'check_values'(IN Autoridad VARCHAR, IN TipoVehiculo VARCHAR)

Finally, you may wish to review the logic in your IF statements. As written they will always be true and the procedure will always SIGNAL SQLSTATE '45000'. For example, if Autoridad == 'Fiscalia' then the term Autoridad <> 'Transito' will be True which means, when combined with 'OR', as you are doing, the whole predicate is true. Typically what you seem to be attempting is coded as either

IF((Autoridad <> 'Transito') AND (Autoridad <> 'Fiscalia') AND (Autoridad <> 'Pol_Car') AND (Autoridad <> 'Juzgado')) THEN

or equally effective

IF NOT ((Autoridad == 'Transito') OR (Autoridad = 'Fiscalia')  OR (Autoridad == 'Pol_Car') OR (Autoridad == 'Juzgado')) THEN
  • Now is giving me a syntax error in this line: ```IF NOT ((Autoridad == 'Transito') OR (Autoridad = 'Fiscalia') OR (Autoridad == 'Pol_Car') OR (Autoridad == 'Juzgado')) THEN``` – Draken Jun 18 '19 at 13:05