jonllen 2009-04-08 01:10
浏览 248
已采纳

Java连MySql数据库存储过程内使用while循环递归至分类根节点的问题~~

label_proc:
begin
    declare v_category_inner_code int;
    declare v_rootid int default null;
    declare v_tempid int default null;
    declare v_listid varchar(1000) default 'aaa';
    set v_category_inner_code = p_category_inner_code;
    while (v_category_inner_code is  not null)
    do
    begin
        if  exists (select *   from pu_productcategory where category_inner_code = v_category_inner_code) then
            select category_inner_code,up_inner_code into v_tempid,v_category_inner_code  from pu_productcategory where category_inner_code = v_category_inner_code;
        else
            select v_category_inner_code;
            set v_category_inner_code = null;
        end if;

    end;
    end while;
    select * from pu_productcategory where category_inner_code = v_category_inner_code;
end label_proc
如上代码:mySQL存储过程 需传入一个参数p_category_inner_code int,数据表结构主要就一个category_inner_code分类编号 和上up_inner_code上级分类编号,我想根据p_category_inner_code 传入的参数递归查询
出该分类的最根级分类,就一个while简单的循环不错那里了,就是没结果出来,好象变成死循环了,我感觉我做的没错啊,希望高手来解决,本人mysql新手。

 呵呵,自己解决了,错在这步:select category_inner_code,up_inner_code into v_tempid,v_category_inner_code  from pu_productcategory where category_inner_code = v_category_inner_code;原本是想根据v_category_inner_code来取记录并把up_inner_code 给v_category_inner_code赋值一步完成,下次递归循环查询的就是ID为这条记录的上级分类,但是MYSQL这里却不能很好的处理这个v_category_inner_code作为条件又给它赋值的操作,语法是没错误的,但是结果就是不出来,运行时还提示的结果超过多行错误!

  • 写回答

1条回答 默认 最新

  • wanghaolovezlq 2009-04-15 22:58
    关注

    自己多想想就能出来了嘛,

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题