Error en funcion
Publicado por Lorenzo (1 intervención) el 19/01/2021 22:09:22
Buenas, soy nuevo con MySQL y estoy tratando de crear una funcion que reciba los parametros de una nueva cuenta y los agregue a sus respectivas tablas, pero me esta dando error y no logro dar con el mismo.
La sentencia es:
La sentencia es:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
CREATE FUNCTION insert_account(account_type INT, name_ VARCHAR(20), last_name_ VARCHAR(20), document_ INT, gender_ TINYINT(1), active_ TINYINT(1)) RETURNS TINYINT(1)
BEGIN
DECLARE result TINYINT(1);
DECLARE professor_id INT;
DECLARE student_id INT;
SET result =0;
IF account_type = 1 THEN
add_admin:BEGIN
INSERT INTO person (document, name, last_name, gender)
VALUES (document_, name_, last_name_, gender_);
INSERT INTO account (user_name, pass, type, person_id)
VALUES (document_, professor_id, account_type, document_);
SET result =1;
END add_admin
ELSEIF account_type = 2 THEN
add_student: BEGIN
SET student_id = SELECT COUNT(*) FROM student
SET student_id = student_id+1;
INSERT INTO student (file_id, person_id)
VALUES (student_id, document_);
INSERT INTO person (document, name, last_name, gender)
VALUES (document_, name_, last_name_, gender_);
INSERT INTO account (user_name, pass, type, person_id)
VALUES (document_, student_id, account_type, document_);
SET result = 1;
END add_student
ELSE
add_professor BEGIN
SET professor_id = SELECT COUNT(*) FROM professor
SET professor_id = professor_id+1;
INSERT INTO professor (file_id, person_id, active)
VALUES (professor_id, document_, active_);
INSERT INTO person (document, name, last_name, gender)
VALUES (document_, name_, last_name_, gender_);
SET result = 1;
END add_professor
RETURN result;
END
Valora esta pregunta


0