在SQL中使用游标的递归函数 [英] Recursive function using Cursor in SQL

查看:89
本文介绍了在SQL中使用游标的递归函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在类别表(同一个表)中有父类别ID.添加类别时,有两个选项.如果我们创建新类别而不选择退出类别,则第一个类别将成为其父类别.第二个,如果我们通过选择退出类别创建类别,那么所选类别将成为父类别.所以现在我想通过在SQL上使用Cusor和递归函数来选择所有类别和子类别.这个有可能?

I have parentcategory id in the category table.(same table). When add category there is two options. First one if we create new category without selecting the exitence category than its became the parent category. Second one if we create the category with select the exitence category that selected category become the parentcategory. So now i want to select all the category and subcategory by using Cusor and recursive function on sql. This is possible? How?

推荐答案

如果您使用的是Sqlserver,则有关如何使用公用表表达式的很好的解释 ^ ].
如果您使用的是Oracle,则还有更多选择.看看这里 [此处 [^ ].
If you''re using Sqlserver there is a good explanation on how to use common table expressions here[^].
If you''re using Oracle you have a lot more options. Have a look here[^] and here[^].


这篇关于在SQL中使用游标的递归函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆