sql - mySQL Stored Procedure - Cursor error -


i'm trying write mysql procedure cursor calculate fare. pass in stationid's figure out zone in. fare set value of $1 , additional $0.20 each zone traveled in. code have far runs there problem cursor not fetching values variables.

any appreciated. thanks

tables:

    drop database if exists luassystem;     create database luassystem;     use luassystem;      create table if not exists line     (     line_id int not null auto_increment,     line_colour char(10) not null,     primary key (line_id)     )   engine=innodb;      create table if not exists zone     (     zone_id int not null auto_increment,     zone_name varchar(20) not null,         line int not null,     primary key (zone_id),     foreign key (line) references line(line_id) on update cascade on delete restrict     )   engine=innodb;      create table if not exists station     (     station_id int not null auto_increment,     station_name char(20) not null,     service char(20),         line int not null,         zone int not null,     primary key (station_id),     foreign key (line) references line(line_id) on update cascade on delete restrict,     foreign key (zone) references zone(zone_id) on update cascade on delete restrict     )   engine=innodb; 

stored procedure:

    drop procedure if exists calculatefare;     delimiter //     create procedure calculatefare     (     in stationid1 int, in stationid2 int     )     begin      declare zonenum1 int;     declare zonenum2 int;     declare num int;     declare fare double;      declare tableend boolean;      declare zonecur cursor     select zone, zone station     station_name = stationid1 , station_name = stationid2;      declare continue handler not found     set tableend = true;      open zonecur;     the_loop: loop      fetch zonecur     zonenum1, zonenum2;      if tableend     close zonecur;     leave the_loop;     end if;      set fare = 1;     set num = 0;      if zonenum1 < zonenum2     set num = zonenum2 - zonenum1;     elseif zonenum1 > zonenum2     set num = zonenum1 - zonenum2;     end if;      set fare = (num * 0.20) + 1;     select fare;     end loop the_loop;     end //     delimiter ;      call calculatefare(3,5); 

wouldn't easier of used decimal values instead of integers? suggest @ : http://dev.mysql.com/doc/refman/5.0/en/fixed-point-types.html


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -