1

我在 MySQL 中有一个存储函数,它可以部分工作。

DELIMITER $$
DROP FUNCTION IF EXISTS `getsubdomain`$$
CREATE FUNCTION getsubdomain(page_id int(11))
RETURNS CHAR(255)
DETERMINISTIC
READS SQL DATA
SQL SECURITY INVOKER
BEGIN
declare current_p_id int(11);
declare current_p_parent_id int(11);
declare current_p_address_type char(255);
declare current_p_adress char(255);
SET current_p_id = page_id;
WHILE (current_p_id) <> 0
DO
select p_parent_id, p_address_type, p_adress from opu_pages where p_id = current_p_id into current_p_parent_id, current_p_address_type, current_p_adress;
IF current_p_address_type <> ''
THEN
IF current_p_address_type = 'subdomain'
THEN
RETURN current_p_adress;
ELSE
SET current_p_id = current_p_parent_id;
END IF;
ELSE
RETURN NULL;
END IF;
END WHILE;
RETURN NULL;
END$$
DELIMITER ;

如果我打电话查询SELECT getsubdomain(p_id) FROM opu_pages;它可以正常工作。但是如果我在SELECT * FROM opu_pages WHERE getsubdomain(p_id)='library';数据库中调用它就会崩溃并冻结。查询和函数使用一张表。我做错了什么?我认为这可能是由表格式 MyISAM 引起的。但我无法将其更改为 InnoDB,因为我在此表中使用了 FULLTEXTFORMAT 字段。

opu_pages(MyISAM)方案

p_id INT
p_parent_id INT
p_address_type ENUM (path, subdomain)
p_adress VARCHAR
4

1 回答 1

0

Based on your post I would say that your code is entering an infinite loop for some of your input parameters.

In particular the case where p_id = p_parent_id in the opu_pages table and the current_p_address_type = 'subdomain'

于 2012-03-19T09:33:46.173 回答