MySQL Reverse recursive tree query

Source: Internet
Author: User

Create a MySQL function Fun_knowledge_child_url, enter an int type node Chid,return a URL string

Begin declare stemp varchar (         declare);  stempchd varchar (         declare knoname);  varchar (;         declare temppid int; )  SET sTemp =  ' $ '; set knoname =  ' $ '; set temppid = chid; Select t3. ' Name '  into stemp  from mooc_si_knowledge_tree t3 where  t3.id = chId;        WHILE tempPid>0  doselect t.pid into temppid  from mooc_si_knowledge_tree t where  t.id = temppid;        if temppid>0thenselect  T2. ' Name '  INTO knoName FROM mooc_si_knowledge_tree t2 where t2.id=tempPid; Set stemp = conCAT (Knoname, '/', stemp); end if; end while; return stemp; END


MySQL Reverse recursive tree query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.