我有如下函數被添加到MySQL數據庫我已經嘗試通過phpMyAdmin,但它沒有給我指示是否添加或不當,當我嘗試運行該函數給出錯誤的功能不存在。我在這裏失蹤的任何東西?通過phpMyAdmin添加一個mysql函數
DELIMITER //
CREATE FUNCTION GISWithin(pt POINT, mp MULTIPOLYGON) RETURNS INT(1) DETERMINISTIC
BEGIN
DECLARE str, xy TEXT;
DECLARE x, y, p1x, p1y, p2x, p2y, m, xinters DECIMAL(16, 13) DEFAULT 0;
DECLARE counter INT DEFAULT 0;
DECLARE p, pb, pe INT DEFAULT 0;
SELECT MBRWithin(pt, mp) INTO p;
IF p != 1 OR ISNULL(p) THEN
RETURN p;
END IF;
SELECT X(pt), Y(pt), ASTEXT(mp) INTO x, y, str;
SET str = REPLACE(str, 'POLYGON((','');
SET str = REPLACE(str, '))', '');
SET str = CONCAT(str, ',');
SET pb = 1;
SET pe = LOCATE(',', str);
SET xy = SUBSTRING(str, pb, pe - pb);
SET p = INSTR(xy, ' ');
SET p1x = SUBSTRING(xy, 1, p - 1);
SET p1y = SUBSTRING(xy, p + 1);
SET str = CONCAT(str, xy, ',');
WHILE pe > 0 DO
SET xy = SUBSTRING(str, pb, pe - pb);
SET p = INSTR(xy, ' ');
SET p2x = SUBSTRING(xy, 1, p - 1);
SET p2y = SUBSTRING(xy, p + 1);
IF p1y < p2y THEN SET m = p1y; ELSE SET m = p2y; END IF;
IF y > m THEN
IF p1y > p2y THEN SET m = p1y; ELSE SET m = p2y; END IF;
IF y <= m THEN
IF p1x > p2x THEN SET m = p1x; ELSE SET m = p2x; END IF;
IF x <= m THEN
IF p1y != p2y THEN
SET xinters = (y - p1y) * (p2x - p1x)/(p2y - p1y) + p1x;
END IF;
IF p1x = p2x OR x <= xinters THEN
SET counter = counter + 1;
END IF;
END IF;
END IF;
END IF;
SET p1x = p2x;
SET p1y = p2y;
SET pb = pe + 1;
SET pe = LOCATE(',', str, pb);
END WHILE;
RETURN counter % 2;
END;
DELIMITER ;
我試圖結束//我得到這個錯誤。您的SQL查詢似乎有錯誤。下面的MySQL服務器的錯誤輸出,如果有任何,也可以幫助你診斷問題 錯誤:未知的標點符號字符串@ 10 STR:// SQL:ELIMITER // CREATE FUNCTION GISWithin(pt點,熔點MULTIPOLYGON)RETURNS INT(1)確定性 BEGIN DECLARE str,xy TEXT; – newbie14
看起來像phpMyAdmin不尊重或不瞭解'DELIMITER',因爲它只是一個MySQL CLI客戶端命令。根據這篇文章,phpMyAdmin中有一個文本框來設置分隔符。在那裏輸入你的'//',並從你的代碼中刪除'DELIMITER'語句。 http://forums.mysql.com/read.php?98126320,247753#msg-247753 –
你是救世主! – saada