You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Oracle SQL从大CLOB字段提取指定目标单词?

Solution to Extract Exact Status Keywords from CLOB

Got it, let's sort this out for you. The problem with your existing queries is that they’re just pulling arbitrary slices of the CLOB instead of zeroing in on the exact status terms you need. Here’s how to directly extract only Available, Not Available, or Ordered from the most recent response:

SELECT REGEXP_SUBSTR(response, 'Available|Not Available|Ordered', 1, 1, 'i') AS extracted_status
FROM (
    SELECT response
    FROM t_leg
    WHERE service = UPPER('LETO87')
    ORDER BY search_date DESC
)
WHERE ROWNUM < 2;

Breakdown of the Query:

  • Inner Subquery: First, we fetch the most recent record for LETO87 by sorting search_date in descending order and limiting to the top result with ROWNUM < 2.
  • REGEXP_SUBSTR: This function scans the response CLOB for the first occurrence of any of your target terms. The 'i' flag makes the match case-insensitive (remove it if you need strict case matching).

For Older Oracle Versions (Pre-11g)

If your Oracle version doesn’t support regex operations directly on CLOBs, wrap the CLOB in DBMS_LOB.SUBSTR to convert a segment to VARCHAR2 first (adjust the length/start position if your target term might be further into the CLOB):

SELECT REGEXP_SUBSTR(
    DBMS_LOB.SUBSTR(response, 4000, 1), -- Grab first 4000 characters of the CLOB
    'Available|Not Available|Ordered', 
    1, 1, 'i'
) AS extracted_status
FROM (
    SELECT response
    FROM t_leg
    WHERE service = UPPER('LETO87')
    ORDER BY search_date DESC
)
WHERE ROWNUM < 2;

This will return only the exact status term you’re looking for, no extra irrelevant text.

内容的提问来源于stack exchange,提问作者Stef

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:19:31