Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9155297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:34:00+00:00 2026-06-17T12:34:00+00:00

I have a web service that pulls text from an NCLOB column and returns

  • 0

I have a web service that pulls text from an NCLOB column and returns the data via XML. The NCLOB column is populated by extracting text from documents, so there are occasions where invalid XML characters are placed in the XML, causing the consuming system to fail.

As per the W3C, the range of valid characters is:

#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
/* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */

We have tried a few different RegExp patterns, and we’re close, but we’re not completely there yet. Here is the closest we’ve come. All of the invalid characters are replaced except for the high surrogates (DB9B – DBFF).

REGEXP_REPLACE(
    TEXT,
    '[^[:print:]' || chr(13) || chr(10) || ']|[' || UNISTR('\FFFE-\FFFF') || ']',
    '*')

We have also tried this, but none of the surrogates (D800 – DFFE) are replaced.

REGEXP_REPLACE(REPLACE(TEXT, unistr('\0000'), ' '),
      '[' || unistr('\0001-\0008') || ']' 
  || '|[' || unistr('\000B-\000C') || ']'
  || '|[' || unistr('\000E-\001F') || ']'
  || '|[' || unistr('\D800-\DFFF') || ']' 
  || '|[' || unistr('\FFFE-\FFFF') || ']',' ')

How can we match the high surrogates? Any thoughts or guidance would be most appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:34:01+00:00Added an answer on June 17, 2026 at 12:34 pm

    You could write your own function since regex_replace does not seem to work for the high surrogates. Here’s an example (tested on 9.2 and 11.2):

    CREATE OR REPLACE FUNCTION replace_invalid(p_clob NCLOB) RETURN NCLOB IS
       l_result NCLOB;
       l_char   NVARCHAR2(1 char);
    BEGIN
       FOR i IN 1 .. length(p_clob) LOOP
          l_char := substr(p_clob, i, 1);
          IF utl_raw.cast_to_binary_integer(utl_raw.cast_to_raw(l_char)) 
              BETWEEN to_number('DB9B', 'xxxx') AND to_number('DBFF', 'xxxx') THEN
             l_result := l_result || N'*';
          ELSE
             l_result := l_result || l_char;
          END IF;
       END LOOP;
       RETURN l_result;
    END;
    

    It should run with large NCLOB, here’s an example with a clob > 32k characters:

    SQL> DECLARE
      2     l_in  NCLOB;
      3     l_out NCLOB;
      4  BEGIN
      5     FOR i IN 1 .. to_number('DBFF', 'xxxx') LOOP
      6        l_in := l_in || nchr(i);
      7     END LOOP;
      8     dbms_output.put_line('l_in length:' || length(l_in));
      9     l_out := replace_invalid(l_in);
     10     dbms_output.put_line('l_out length:' || length(l_out));
     11     dbms_output.put_line('chars replaced:' 
     12                        || (length(l_out) - length(REPLACE(l_out, '*', ''))));
     13  END;
     14  /
    
    l_in length:56319
    l_out length:56319
    chars replaced:102
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iOS app that pulls user data down from a web service
I have a script that pulls some data from a web service and populates
I have a web service that returns this string via the jQuery $.ajax() call
Right, this is an odd one. We have a web service that returns data
I have a web service class that successfully pulls my JSON from a feed
I have a function in a service that basically pulls the data from a
I have an application that pulls data from several web services. The application is
I've got a little c# windows service that periodically pulls xml from a web
I have a web service that stores data in a local SQL Server 2008
I have a web service that returns me a JSON object that contains the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.