Stored Procedures in MySQL

nonte

New Member
Messages
55
Reaction score
0
Points
0
Has anyone been able to create SPs in MySQL in the free hosting service. I am pasting the code here. It's working fine in my local machine.

drop procedure if exists BuildRoutes;
delimiter |
create procedure BuildRoutes()
begin
declare rows int default 0;
truncate routes;
insert into routes
select null,depart,arrive,1,id,distance,time from edges;
set rows=row_count();
while (rows>0) do
create or replace view nextroutes as
select routes.depart,edges.arrive,routes.hops+1 as hops,(routes.distance+edges.distance) as distance, concat(routes.route,',',edges.id) as route,min(routes.time+edges.time) as time from routes inner join edges on routes.arrive=edges.depart and locate(edges.arrive,routes.route)=0 group by depart,arrive;
insert into routes
select null,nextroutes.depart,nextroutes.arrive,nextroutes.hops,nextroutes.route,nextroutes.distance,nextroutes.time from nextroutes left join routes on nextroutes.depart=routes.depart and nextroutes.arrive=routes.arrive where routes.depart is null and routes.arrive is null;
set rows=row_count();
update routes,nextroutes set routes.hops=nextroutes.hops,routes.route=nextroutes.route,routes.distance=nextroutes.distance,routes.time=nextroutes.time where routes.arrive=nextroutes.arrive and routes.depart=nextroutes.depart and nextroutes.time<routes.time;
set rows=rows+row_count();
end while;
end;
|

Help me out please.
 

wechchile

New Member
Messages
4
Reaction score
0
Points
0
Puede Escribir El Procedura En Forma Mas Ordenada
Para Poder Ayudate
Edit:
.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #f5f5ff; background-image: none; color: #496292; font-family: Tahoma, Verdana, Arial, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 11px; line-height: normal } p { margin: 0px; }BUSCA *UN PROGRAMA LLADO NAVICA ES UN PROGRA QUE AYUDA PARA PROGRAMAR LOS PORCEDURE
 
Last edited:

patchnpuki

New Member
Messages
6
Reaction score
0
Points
0
I spent all day trying to get this to work and it seems that changing the delimiter doesn't work on X10. I eventually managed to get round this problem by rewriting my procedure so it was only one line.

Original version:

CREATE PROCEDURE loadOutwardRunPOI(IN gear1 INT, IN gear2 INT, IN gear3 INT)
BEGIN
SET @runId=LAST_INSERT_ID();
INSERT INTO RunPOI VALUES (@runId,@nthwayId,NULL,NULL,gear1,'');
INSERT INTO RunPOI VALUES (@runId,@budgetId,NULL,NULL,gear2,'');
INSERT INTO RunPOI VALUES (@runId,@jupiterId,NULL,NULL,gear3,'');
END;

One line version:

CREATE PROCEDURE loadOutwardRunPOI(IN gear1 INT, IN gear2 INT, IN gear3 INT)
INSERT INTO RunPOI VALUES (LAST_INSERT_ID(),@nthwayId,NULL,NULL,gear1,''),
(LAST_INSERT_ID(),@budgetId,NULL,NULL,gear2,''),
(LAST_INSERT_ID(),@jupiterId,NULL,NULL,gear3,'');

Unfortunately I don't think you will be able to do this with your procedure, but it may be of use to other users.
 
Top