I created two procedures for insert and delete respectively and would like to add them into just one procedure separated according to user's output. Any suggestions on how to do that?
create table departamento (
dnome varchar(100),
dnumero int primary key,
cpf_gerente bigint,
data_inicio_gerente date
);
Insert procedure:
delimiter //
create procedure inserir_departamento(in pr_dnome varchar(100), in pr_dnumero int, in pr_cpf_gerente bigint, in pr_data_inicio_gerente date)
begin
insert into departamento values(pr_dnome, pr_dnumero, pr_cpf_gerente,pr_data_inicio_gerente);
end //
delimiter ;
#drop procedure inserir_departamento;
call inserir_departamento('Teste', 6, 99988777767,'1978-11-11');
Delete procedure:
delimiter $$
create procedure deletar_departamento(in pr_dnumero int)
begin
delete from departamento
where dnumero = pr_dnumero;
end $$
delimiter ;
#drop procedure deletar_departamento;
call deletar_departamento(6);
I tried doing this to "mix" both procedures, but without success (I just receive a syntax error message):
delimiter $$
create procedure modificar_departamento(in insert enum("i"), in delete enum("d"), in pr_dnome varchar(100), in pr_dnumero int, in pr_cpf_gerente bigint, in pr_data_inicio_gerente date)
begin
if insert == "i" then
insert into departamento values(pr_dnome, pr_dnumero, pr_cpf_gerente,pr_data_inicio_gerente);
else if delete == "d" then
delete from departamento where dnumero = pr_dnumero;
end if;
end $$
delimiter ;
Any idea on how to do that?
CodePudding user response:
=
not ==
. elseif
not else if
. Don't use reserved words as variable or parameter names, or if you do put them in backticks.