在sql中动态创建变量 [英] Create variables in sql dynamically

查看:76
本文介绍了在sql中动态创建变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个存储过程,该过程将生成类别列表(多级)的父子关系.我正在尝试在存储过程中生成新变量.请帮我解决代码.

类别列表:

I am writing a stored procedure that would generate parent-child relation of a category list(multi-level). There I am trying to generate new variables in a stored procedure. Please help me out with the code.

Category list:

cat1
cat1>>sub1
cat1>>sub2
cat1>>sub2>>sub22...


推荐答案

,您无需创建动态变量.您可以使用可以使用递归逻辑来获取所有子节点.
请检查以下内容

SQL代码遍历具有父子关系的自引用表 [ http://stackoverflow.com/questions/207309/sql-query-for-parent- child-relationship [ ^ ]
you don''t need to create dynamic variables. you can use can use recursive logic to get all child nodes.
pl check the following

SQL code to traverse self-referencing tables with parent-child relationships[^]

using CTE

http://stackoverflow.com/questions/207309/sql-query-for-parent-child-relationship[^]


这篇关于在sql中动态创建变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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