【问题标题】:How to avoid extra whitespace produced by Teradata's XMLCONCAT and XMLAGG如何避免 Teradata 的 XMLCONCAT 和 XMLAGG 产生的额外空白
【发布时间】:2021-05-07 11:54:02
【问题描述】:

当使用XMLAGGXMLCONCAT 时,Teradata 似乎在连接的内容之间添加了额外的空格:

with t (x) as (select 1)
select 
  xmlserialize(content xmlconcat(1, 2, 3) as varchar(1000)) a,
  xmlserialize(content xmlagg(v order by v) as varchar(1000)) b
from (
  select 1 from t
  union all
  select 2 from t
  union all
  select 3 from t
) as u (v)

以上产生:

|a    |b    |
|-----|-----|
|1 2 3|1 2 3|

有什么方法可以避免 XML 连接产生的额外空白伪影并得到它吗?

|a  |b  |
|---|---|
|123|123|

【问题讨论】:

    标签: sql teradata sqlxml


    【解决方案1】:

    一个明显的技巧是在连接过程中引入一个“不可能的”字符序列,然后再次从结果中删除它:

    with t (x) as (select 1)
    select 
      oreplace(
        xmlserialize(content xmlconcat(1, '##', 2, '##', 3) as varchar(1000)), 
        ' ## '
      ) a,
      oreplace(
        oreplace(
          xmlserialize(content xmlagg(trim(v || '##') order by v) as varchar(1000)),
          '## '
        ), '##'
      ) b
    from (
      select 1 from t
      union all
      select 2 from t
      union all
      select 3 from t
    ) as u (v)
    

    现在的结果是:

    |a  |b  |
    |---|---|
    |123|123|
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-26
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 2018-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多