sql递归查询(包含mysql、pgsql、oracle) |
您所在的位置:网站首页 › oracle递归查询树 › sql递归查询(包含mysql、pgsql、oracle) |
一.postgresql
表格式如下 结果如下: 现在有一个新的需求,求出所有组织机构下面乡村、城镇,并用逗号隔开。效果如下: 语法: 查询语句 start with 起始条件 connect by prior 递归条件1.向下递归(从子节点开始) 之所以把mysql放到最后,是因为mysql中没有实现递归的函数。 因此我们需要自己定义函数 原文地址:https://blog.csdn.net/lilizhou2008/article/details/108505353 delimiter $$ drop function if exists get_child_list$$ create function get_child_list(in_id varchar(10)) returns varchar(1000) begin declare ids varchar(1000) default ''; declare tempids varchar(1000); set tempids = in_id; while tempids is not null do set ids = CONCAT_WS(',',ids,tempids); select GROUP_CONCAT(id) into tempids from t_org_test where FIND_IN_SET(parent_id,tempids)>0; end while; return ids; end $$ delimiter ;然后调用函数 如果报错:This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 在MySQL中创建函数时出现这种错误的解决方法:set global log_bin_trust_function_creators=TRUE; 原文地址:https://blog.csdn.net/topasstem8/article/details/8216740/ |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |