Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Smarty 2.37 KB | None | 0 0
  1. --- I've been trying to run this
  2.  
  3. DELIMITER $$
  4.  
  5. CREATE PROCEDURE TwoBus(in locf int, in loct int, out busid1 int, out busid2 int, out chover int)
  6. BEGIN
  7.     DECLARE  cur_chover CURSOR FOR
  8.     SELECT  changeid FROM changeover;
  9.  
  10.     DECLARE  CONTINUE HANDLER FOR NOT FOUND
  11.  
  12.     OPEN cur_chover;
  13.  
  14.     FETCH cur_chover INTO chover;
  15.  
  16.     CREATE TEMPORARY TABLE TempTable (achover int, abusid1 int, abusid2 int);
  17.  
  18.     DECLARE x INT;
  19.     SET x = 30;
  20.  
  21.     REPEAT
  22.         SET busid1 = 9999;
  23.         SET busid2 = 9999;
  24.  
  25.         SELECT s1.bid INTO busid1
  26.         FROM stop AS s1
  27.         WHERE s1.pid = chover
  28.         AND s1.bid IN ( SELECT s2.bid
  29.                 FROM stop AS s2
  30.                 WHERE s2.pid = locf AND s2.stopNo < s1.stopNo );
  31.  
  32.         SELECT s1.bid INTO busid2
  33.         FROM stop AS s1
  34.         WHERE s1.pid = loct
  35.         AND s1.bid IN ( SELECT s2.bid
  36.                 FROM stop AS s2
  37.                 WHERE s2.pid = chover AND s2.stopNo < s1.stopNo );
  38.  
  39.         IF busid1 < 9999 AND busid2 < 9999 THEN
  40.             INSERT INTO TempTable(achover, abusid1, abusid2)
  41.             VALUES(chover, busid1, busid2);
  42.         ENDIF;
  43.  
  44.         FETCH cur_chover INTO chover;
  45.  
  46.         SET x = x - 1;
  47.  
  48.     UNTIL x = 0
  49.     END REPEAT;
  50.  
  51.     CLOSE cur_chover;
  52.  
  53.     SELECT * FROM TempTable;
  54.  
  55. END$$
  56.  
  57. DELIMITER;
  58.  
  59.  
  60. /***** and it gives me this error:
  61.  
  62. Error
  63.  
  64. SQL query: Documentation
  65.  
  66. 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[...]
  67.  
  68. MySQL said: Documentation
  69. #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;
  70.    SET x = 30;
  71.  
  72.    REPEAT
  73.        SET busid1 = 9999;
  74.        SET busid2 = 99' at line 14
  75.  
  76. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement