简体   繁体   English

SAP HANA 中的 WITH RECURSIVE 公用表表达式

[英]WITH RECURSIVE Common Table Expressions in SAP HANA

I'm really at a loss why I can't get this recursive CTE to work in HANA.我真的不知道为什么我不能让这个递归 CTE 在 HANA 中工作。 We're on HANA 2 so from what I understand it should be supported if I put it in a procedure as SQLSCRIPT.我们在 HANA 2 上,所以据我所知,如果我将它作为 SQLSCRIPT 放在一个过程中,它应该得到支持。 We don't want to use the built in hierarchy functions since we're trying to not use proprietary solutions where possible.我们不想使用内置的层次结构函数,因为我们试图尽可能不使用专有解决方案。

It's not recognizing the nested (INNER JOIN) portion of the CTE.它无法识别 CTE 的嵌套 (INNER JOIN) 部分。 I've tried everything and it says it doesn't find it in my personal schema which is telling me it's interpreting it as a table.我已经尝试了所有方法,但它说在我的个人模式中找不到它,这告诉我它正在将其解释为表格。

Error:错误:

[Location_In_Repository] Dependent object not found: SqlScript; [Location_In_Repository] ​​未找到依赖对象:SqlScript; USERSCHEMA.USER_HIER: symbol not found USERSCHEMA.USER_HIER:未找到符号

BEGIN
WITH USER_HIER AS (
    
SELECT USER_ID, MANAGER_ID
FROM HR.DIM_USER_V

UNION ALL

SELECT hier.USER_ID, hier.MANAGER_ID 
FROM HR.DIM_USER_V hier
    INNER JOIN USER_HIER ON USER_HIER.USER_ID = hier.MANAGER_ID)
SELECT * 
FROM USER_HIER;
END

The most recent HANA 2 documentation clearly states:最新的 HANA 2 文档明确指出:

The <with_clause> cannot support recursive query expressions. <with_clause> 不能支持递归查询表达式。

The hierarchy functions are the way to go here for HANA.层次函数是 HANA 的方法。 While these are of course proprietary, so are most implementations of recursive SELECTs (see https://www.wikiwand.com/en/Hierarchical_and_recursive_queries_in_SQL ).虽然这些当然是专有的,但递归 SELECT 的大多数实现也是专有的(参见https://www.wikiwand.com/en/Hierarchical_and_recursive_queries_in_SQL )。

I'd recommend encapsulating the hierarchy processing into a view or a table function - that way, it is straightforward to exchange the implementation detail when porting to a different DBMS.我建议将层次结构处理封装到视图或表函数中 - 这样,在移植到不同的 DBMS 时就可以直接交换实现细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM