【问题标题】:WITH clause within EA Sparx queryEA Sparx 查询中的 WITH 子句
【发布时间】:2018-09-20 09:26:54
【问题描述】:

是否可以在 EA Sparx 查询中使用 WITH 子句?

这是我写的:

with Activities as

    (
    select t_connector.start_object_id as Object2_id, t_object.* from t_object 
        join t_connector on t_connector.end_object_id=t_object.Object_id
        where t_object.Object_type= 'Activity'

    union

    select t_connector.end_object_id as Object2_id, t_object.*  from t_object  
        join t_connector on t_connector.start_object_id=t_object.Object_id
        where t_object.Object_type= 'Activity'

    )

select * from

    (
    select obj.object_id, count(other.object_id) as 'Activities' from
        t_object obj left join Activities as other on obj.Object_id=other.Object2_id

    group by obj.object_id
    ) as ac 

where object_id in (143306, 143321, 143226, 143326)

它不会返回任何行,也不会抛出任何错误,而内嵌 WITH 语句的相同查询会返回预期结果:

select * from
    (
    select obj.object_id, count(other.object_id) as 'Activities' from
        t_object obj left join 
            (
            select t_connector.start_object_id as Object2_id, t_object.* from t_object 
                join t_connector on t_connector.end_object_id=t_object.Object_id
                where t_object.Object_type= 'Activity'

            union

            select t_connector.end_object_id as Object2_id, t_object.*  from t_object  
                join t_connector on t_connector.start_object_id=t_object.Object_id
                where t_object.Object_type= 'Activity'

            )
        as other on obj.Object_id=other.Object2_id

    group by obj.object_id
    ) as ac 

where object_id in (143306, 143321, 143226, 143326)

我知道 EA 的 SQL 引擎有点棘手(例如查询不能以注释开始)。

这里有一些技巧可以让 WITH 子句在 EA 中工作吗?

【问题讨论】:

    标签: enterprise-architect


    【解决方案1】:

    EA 对查询进行一些基本检查。其中之一是检查查询是否以关键字select 开头。

    因此,没有办法让 EA 执行以 select 开头的其他内容的搜索查询。

    在许多情况下,WITH 子句用于执行递归查询,例如获取包中的所有元素及其所有子包。
    对于这种特定情况,您可以使用宏 #Branch#,它将递归地转换为当前所选包及其所有子包的包 ID 的逗号分隔列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-16
      相关资源
      最近更新 更多