Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- I've been trying to run this
- DELIMITER $$
- CREATE PROCEDURE TwoBus(in locf int, in loct int, out busid1 int, out busid2 int, out chover int)
- BEGIN
- DECLARE cur_chover CURSOR FOR
- SELECT changeid FROM changeover;
- DECLARE CONTINUE HANDLER FOR NOT FOUND
- OPEN cur_chover;
- FETCH cur_chover INTO chover;
- CREATE TEMPORARY TABLE TempTable (achover int, abusid1 int, abusid2 int);
- DECLARE x INT;
- SET x = 30;
- REPEAT
- SET busid1 = 9999;
- SET busid2 = 9999;
- SELECT s1.bid INTO busid1
- FROM stop AS s1
- WHERE s1.pid = chover
- AND s1.bid IN ( SELECT s2.bid
- FROM stop AS s2
- WHERE s2.pid = locf AND s2.stopNo < s1.stopNo );
- SELECT s1.bid INTO busid2
- FROM stop AS s1
- WHERE s1.pid = loct
- AND s1.bid IN ( SELECT s2.bid
- FROM stop AS s2
- WHERE s2.pid = chover AND s2.stopNo < s1.stopNo );
- IF busid1 < 9999 AND busid2 < 9999 THEN
- INSERT INTO TempTable(achover, abusid1, abusid2)
- VALUES(chover, busid1, busid2);
- ENDIF;
- FETCH cur_chover INTO chover;
- SET x = x - 1;
- UNTIL x = 0
- END REPEAT;
- CLOSE cur_chover;
- SELECT * FROM TempTable;
- END$$
- DELIMITER;
- /***** and it gives me this error:
- Error
- SQL query: Documentation
- DELIMITER $$ CREATE PROCEDURE TwoBus(in locf int, in loct int, out busid1 int, out busid2 int, out chover int) BEGIN DECLARE cur_chover CURSOR FOR SELECT changeid FROM changeover; DECLARE CONTINUE HANDLER FOR NOT FOUND OPEN cur_chover; FETCH cur_chover INTO chover; CREATE TEMPORARY TABLE TempTable (achover int, abusid1 int, abusid2 int); DECLARE x INT; SET x = 30; REPEAT SET busid1 = 9999; SET busid2 = 9999; SELECT s1.bid INTO busid1 FROM stop AS s1 WHERE s1.pid = chover AND s1.bid IN ( SELECT s2.bid FROM stop AS s2 WHERE s2.pid = locf AND s2.stopNo < s1.stopNo ); SELECT s1.bid INTO busid2 FROM stop AS s1 WHERE s1.pid = loct AND s1.bid IN ( SELECT s2.bid FROM stop AS s2 WHERE s2.pid = chover AND s2.stopNo < s1.stopNo ); IF busid1 < 9999 AND busid2 < 9999 THEN INSERT INTO TempTable(achover, abusid1, abusid2) VALUES(chover, busid1, busid2); ENDIF; FETCH cur_chover INTO chover[...]
- MySQL said: Documentation
- #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE x INT;
- SET x = 30;
- REPEAT
- SET busid1 = 9999;
- SET busid2 = 99' at line 14
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement