结合XMLAGG和REGEXP_REPLECE

发布于 2025-01-26 04:33:04 字数 1723 浏览 5 评论 0原文

问题:在我使用XMlagg时,具有一些(u+000b)字符的自由形式文本字段,最终出现在文本中,并在我的SQL提取物中造成一些错误:

ORA-64451: Conversion of special character to escaped character failed.

我试图写入Regexp_replace代码以删除这些字符不断出现,但我正在努力完成它。当我运行我编写的Regexp_replace代码以在带有此问题的确认行数据上进行测试时,它运行:

select PARENT_REQUEST_ID,
REGEXP_REPLACE(worklog_details,'\s{2,}', '') as inbound_call_notes
from ARADMIN.FTS_WORKLOG

where worklog_type is not null AND
parent_request_id ='000000001234567'

下面是我一直在尝试将Regexp_replace工作的完整SQL脚本进入:

SELECT 
ti.CUSTOMER_ID as CID,
ti.billing_id as BID,
ti.TROUBLE_ID,
ti.REPORTED_BY,
ti.DISPATCHED,
to_char(to_date('01-JAN-1970','dd-mon-yyyy')+((ti.create_date/60/60-7)/24), 'DD/MM/YYYY HH:MI:SS AM') as createday,
to_char(to_date('01-JAN-1970','dd-mon-yyyy')+((ti.create_date/60/60-7)/24), 'YY-MM') as createmo,
to_char(to_date('01-JAN-1970','dd-mon-yyyy')+((ti.date_closed/60/60-7)/24), 'DD/MM/YYYY HH:MI:SS AM') as closeday,
to_char(to_date('01-JAN-1970','dd-mon-yyyy')+((ti.date_closed/60/60-7)/24), 'YY-MM') as closemo,
ti.CATEGORY1 as CAT1,
ti.CATEGORY2 as CAT2,
ti.CATEGORY3 as CAT3,
inbound_call_notes,
ti.RESOLUTION_CODE1 as RES1,
ti.RESOLUTION_CODE2 as RES2,
ti.RESOLUTION_CODE3 as RES3

FROM
aradmin.fts_ticket ti
LEFT JOIN (select PARENT_REQUEST_ID,
rtrim(xmlagg(xmlelement(e,worklog_details,', ').extract('//text()') order by PARENT_REQUEST_ID).getclobval(),', ') as inbound_call_notes
  from ARADMIN.FTS_WORKLOG
  where worklog_type is not null
  GROUP BY PARENT_REQUEST_ID) wk ON wk.PARENT_REQUEST_ID = ti.TROUBLE_ID

WHERE
ti.trouble_id IN ('000000001234567')

放置Regexp_replace的问题是在rtrim(xmlagg(xmlelement))之前,我是否需要对此有所不同?这是我冒险进入的一些新领域,因此我的经验有限。

Problem: Have free-form text fields with some (U+000B) characters that end up appearing in the text and causing some errors in my SQL extracts when I use XMLAGG:

ORA-64451: Conversion of special character to escaped character failed.

I was attempting to write-in a REGEXP_REPLACE code to remove these characters that keep appearing but I'm struggling to get it to complete. When I run the REGEXP_REPLACE code I've written to test on a confirmed row of data with this problem, it runs:

select PARENT_REQUEST_ID,
REGEXP_REPLACE(worklog_details,'\s{2,}', '') as inbound_call_notes
from ARADMIN.FTS_WORKLOG

where worklog_type is not null AND
parent_request_id ='000000001234567'

Below is the full SQL script I've been trying to work the REGEXP_REPLACE into:

SELECT 
ti.CUSTOMER_ID as CID,
ti.billing_id as BID,
ti.TROUBLE_ID,
ti.REPORTED_BY,
ti.DISPATCHED,
to_char(to_date('01-JAN-1970','dd-mon-yyyy')+((ti.create_date/60/60-7)/24), 'DD/MM/YYYY HH:MI:SS AM') as createday,
to_char(to_date('01-JAN-1970','dd-mon-yyyy')+((ti.create_date/60/60-7)/24), 'YY-MM') as createmo,
to_char(to_date('01-JAN-1970','dd-mon-yyyy')+((ti.date_closed/60/60-7)/24), 'DD/MM/YYYY HH:MI:SS AM') as closeday,
to_char(to_date('01-JAN-1970','dd-mon-yyyy')+((ti.date_closed/60/60-7)/24), 'YY-MM') as closemo,
ti.CATEGORY1 as CAT1,
ti.CATEGORY2 as CAT2,
ti.CATEGORY3 as CAT3,
inbound_call_notes,
ti.RESOLUTION_CODE1 as RES1,
ti.RESOLUTION_CODE2 as RES2,
ti.RESOLUTION_CODE3 as RES3

FROM
aradmin.fts_ticket ti
LEFT JOIN (select PARENT_REQUEST_ID,
rtrim(xmlagg(xmlelement(e,worklog_details,', ').extract('//text()') order by PARENT_REQUEST_ID).getclobval(),', ') as inbound_call_notes
  from ARADMIN.FTS_WORKLOG
  where worklog_type is not null
  GROUP BY PARENT_REQUEST_ID) wk ON wk.PARENT_REQUEST_ID = ti.TROUBLE_ID

WHERE
ti.trouble_id IN ('000000001234567')

Is it a matter of putting the REGEXP_REPLACE before rtrim(xmlagg(xmlelement)) or do I need to go about this a little bit differently? This is some newer territory I'm venturing into, so my experience is limited.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜泪 2025-02-02 04:33:05

昨天设法弄清楚如何将Regexp_replace与同事正确整合。这是我所做的:

FROM
aradmin.fts_ticket ti
  LEFT JOIN (select PARENT_REQUEST_ID,
  rtrim(xmlagg(xmlelement(x,REGEXP_REPLACE(worklog_details, '[^[:print:]]', ''),', ').extract('//text()') order by PARENT_REQUEST_ID).getclobval(),', ') as inbound_call_notes
  from ARADMIN.FTS_WORKLOG
  where worklog_type is not null
  GROUP BY PARENT_REQUEST_ID) wk ON wk.PARENT_REQUEST_ID = ti.TROUBLE_ID

Managed to figure out how to integrate REGEXP_REPLACE properly with a coworker yesterday. Here is what I did:

FROM
aradmin.fts_ticket ti
  LEFT JOIN (select PARENT_REQUEST_ID,
  rtrim(xmlagg(xmlelement(x,REGEXP_REPLACE(worklog_details, '[^[:print:]]', ''),', ').extract('//text()') order by PARENT_REQUEST_ID).getclobval(),', ') as inbound_call_notes
  from ARADMIN.FTS_WORKLOG
  where worklog_type is not null
  GROUP BY PARENT_REQUEST_ID) wk ON wk.PARENT_REQUEST_ID = ti.TROUBLE_ID
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文