DELIMITER $$DROP FUNCTION IF EXISTS `test2`.`fn_level`$$CREATE FUNCTION `test2`.`fn_level`(id char(3))
RETURNS int
BEGIN
declare v_level int default 1;
declare total int default 0;
declare cnt int default 0;
create temporary table if not exists t_Level (ID char(3),`Level` int);
insert into t_Level select id,v_level;
select found_rows() into cnt;
while cnt>0
do
SET v_level = v_level+1;
insert into t_Level select tb.ID,v_level
from tb,t_Level where tb.PID=t_Level.ID
and t_Level.Level=v_level-1;
end while;
select count(*) from t_Level into total;
RETURN total;
END$$DELIMITER ;
RETURNS int
BEGIN
declare v_level int default 1;
declare total int default 0;
declare cnt int default 0;
create temporary table if not exists t_Level (ID char(3),`Level` int);
insert into t_Level select id,v_level;
select found_rows() into cnt;
while cnt>0
do
SET v_level = v_level+1;
insert into t_Level select tb.ID,v_level
from tb,t_Level where tb.PID=t_Level.ID
and t_Level.Level=v_level-1;
end while;
select count(*) from t_Level into total;
RETURN total;
END$$DELIMITER ;
解决方案 »
- PHP程序员【求职】-- 北京
- 这个正规该怎么写
- 请问如何保存PHP页面的数值到本地磁盘???
- 有ASP基础,学习PHP有哪些需要注意的?
- 关于录入单引号问题,这次非解决这个问题不可,50分送上
- 请教php中如何让缩略图在浏览器中直接输出?(在线等!)
- 一个急需您解答关于安全下载的问题,online
- CGI Error:The specified CGI application misbehaved by not returning a complete set of HTTP headers.这是什么错误?
- php怎样连接MS_SQLSERVER
- 有没有freebsd+apache+php+mysql的成功的商业网站?
- 奇怪的显示...不解
- 有什么好点的php新闻管理系统源代码么?
经测试,结果和SQLSERVER的返回结果不一样的:(
BEGIN
declare v_level int default 1;
declare total int default 0;
create temporary table if not exists t_Level (ID char(3),`Level` int);
insert into t_Level select id,v_level;
while row_count()!=-1
do
SET v_level = v_level+1;
insert into t_Level select tb.ID,v_level
from tb,t_Level where tb.PID=t_Level.ID
and t_Level.Level=v_level-1;
end while;
select count(*) from t_Level into total;
RETURN total;
END$$DELIMITER ;