Procedimiento almacenado ejercicio cajero
Publicado por Jonathan Pardo (2 intervenciones) el 09/10/2014 03:39:20
Que tal amigos estoy haciendo un ejercicio de un cajero, el cual tengo un procedimiento almacenado que tiene todo el manejo de los movimientos de las cuentas, pero al ejecutarlo tengo un error de sintaxys, y no lo he podido encontrar. ayuda por favor.........
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
///----TABLAS----///
CREATE TABLE Cuentas (
`numero_cuenta` INT NOT NULL,
`nombre_titular` CHAR(45) NULL,
`saldo_cuenta` DOUBLE,
`estado`CHAR(2) NULL,
PRIMARY KEY (`numero_cuenta`))
ENGINE = InnoDB;
CREATE TABLE Movimientos (
`numero_movimientos` INT AUTO_INCREMENT NOT NULL,
`num_cuenta` INT NOT NULL,
`tipo_movimiento` VARCHAR(45) NULL,
`monto` INT NOT NULL,
`fecha_movimiento` DATE NULL,
PRIMARY KEY (`numero_movimientos`),
CONSTRAINT fk_Cuentas
FOREIGN KEY (num_cuenta)
REFERENCES Cuentas (`numero_cuenta`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
//-----INSERTAR VALORES----//
insert into Cuentas values (415,'Juanita',1200000,'ca');
insert into Cuentas values (669,'Jhoan',3500000,'cn');
insert into Cuentas values (221,'Lorena',600000,'cn');
insert into Cuentas values (425,'lola',183000,'ca');
insert into Cuentas values (612,'Raul',225000,'cn');
insert into Cuentas values (506,'Diego',3630000,'ca');
//-----PROCEDIMIENTO----//
delimiter //
create procedure transaccion(IN movimiento int, numeros_cuentas int, total double)
begin
if accion <>0 then
if (select Cuentas.estado from Cuentas where Cuentas.numero_cuenta = numeros_cuentas)='ca' then
case movimiento
when 1 then
if (select numero_cuenta from Cuentas where numero_cuenta= numeros_cuentas)=numeros_cuentas then
update Cuentas set Cuentas.total = saldo_cuenta+total where numeros_cuentas= numero_cuenta;
select total as Nuevo_Saldo from Cuentas where Cuentas.numero_cuenta=numeros_cuentaa;
insert into Movimientos (num_cuenta,tipo_movimiento,monto) values (numeros_cuentas,movimiento,total);
SELECT '//Transaccion Realizada //';
else
select 'La Cuenta No Existe';
end if;
when 2 then
if (select Cuentas.numero_cuenta from Cuentas where numeros_cuentas = Cuentas.numero_cuenta)= numeros_cuentas then
select Cuentas.saldo_cuenta as su_saldo_actual_es from Cuentas where Cuentas.numero_cuenta=numero_cuentas;
INSERT INTO Movimientos
(num_cuenta,tipo_movimiento,monto) values (numeros_cuentas,movimiento, 0);
SELECT '//Transaccion Realizada //';
else
select 'La Cuenta No Existe';
end if;
when 3 then
if (select Cuentas.numero_cuenta from Cuentas where numeros_cuentas=Cuentas.numero_cuenta)=numeros_cuentas then
if(select Cuentas.saldo_cuenta from Cuentas where Cuentas = numeros_cuentas) >= total then
update Cuentas set Cuentas.saldo_cuenta = saldo_cuenta+total where numero_cuenta = numeros_cuentas;
select saldo_cuenta as Nuevo_Saldo_cuenta from Cuentas.numero_cuenta=numeros_cuentas;
INSERT INTO Movimientos
(num_cuenta,tipo_movimiento,monto) values (numeros_cuentas,movimiento, total);
SELECT '//Transaccion Realizada //';
else
select 'Saldo insuficiente';
end if;
rollback;
end if;
else
select 'La Cuenta No Existe';
end if;
end case;
else if (select estado from Cuentas where Cuentas.numero_cuenta = numeros_cuentas) ='cn' then
select " Cuenta Inactiva";
rollback;
end if;
end if;
else
select (' Movimiento No Valido');
end if;
end //
Valora esta pregunta


0