Mam pewną procedurę, którą muszę wstawić z pierwotnej bazy danych do nowej, przystosowanej do obsługi wielu języków, ale nie o to chodzi. Gdy próbuję ją wstawić zapytaniem CREATE PROCEDURE (bezpośrednio przeklejam kod procedury do innej bazy), otrzymuję błąd (w phpMyAdmin):
Kod
Zapytanie SQL:
CREATE DEFINER = `cit1`@`localhost` PROCEDURE `item_count` ( IN p_type_id SMALLINT UNSIGNED ) BEGIN declare v_done TINYINT UNSIGNED DEFAULT 0;
MySQL zwrócił komunikat:
#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 '' at line 5
CREATE DEFINER = `cit1`@`localhost` PROCEDURE `item_count` ( IN p_type_id SMALLINT UNSIGNED ) BEGIN declare v_done TINYINT UNSIGNED DEFAULT 0;
MySQL zwrócił komunikat:
#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 '' at line 5
Oto kod tejże procedury (nie jest mojego autorstwa):
CREATE DEFINER=`cit1`@`localhost` PROCEDURE `item_count`( IN p_type_id smallint UNSIGNED) begin declare v_done tinyint UNSIGNED DEFAULT 0; declare v_depth smallint UNSIGNED DEFAULT 0; CREATE TEMPORARY TABLE hier( parent_type_id smallint UNSIGNED, id smallint UNSIGNED, depth smallint UNSIGNED DEFAULT 0 )engine = memory; INSERT INTO hier SELECT parent_type_id, id, v_depth FROM item_types_view WHERE id = p_type_id; CREATE TEMPORARY TABLE tmp engine=memory SELECT * FROM hier; while NOT v_done do IF EXISTS( SELECT 1 FROM item_types_view p INNER JOIN hier ON p.parent_type_id = hier.id AND hier.depth = v_depth) then INSERT INTO hier SELECT p.parent_type_id, p.id, v_depth + 1 FROM item_types_view p INNER JOIN tmp ON p.parent_type_id = tmp.id AND tmp.depth = v_depth; SET v_depth = v_depth + 1; TRUNCATE TABLE tmp; INSERT INTO tmp SELECT * FROM hier WHERE depth = v_depth; else SET v_done = 1; end IF; end while; SELECT count(tmp_items.id) AS count FROM ( SELECT DISTINCT items.id FROM (SELECT DISTINCT * FROM items) AS items INNER JOIN hier ON hier.id = items.type_id LEFT JOIN districts ON districts.id = items.district_id LEFT JOIN item_types_view p ON items.type_id = p.id WHERE items.is_active = true) tmp_items; DROP TEMPORARY TABLE IF EXISTS hier; DROP TEMPORARY TABLE IF EXISTS tmp; end
Co w tym przypadku generuje błąd? Proszę o pomoc.
Pozdrawiam.