简体   繁体   中英

REGEXP_SUBSTR Hex range in Oracle 11g and Oracle 12c

I am trying to check for certain invalid non-UTF8 characters. From one of the post in this forum, I found this query:

SELECT REGEXP_SUBSTR('This will be my first time visiting Seattle. 😊',
       UNISTR('[\FFFF-\DBFF\DFFF]')) as str FROM dual;

Which gives the following output:

str
-------------------------------------------
😊

But the thing here is when I run the above query on Oracle 12c version, it works totally fine, but when I run the same on Oracle 11g(11.2.0.4) version, I get the following error:

ORA-12728: invalid range in regular expression
12728. 00000 -  "invalid range in regular expression"
*Cause:    An invalid range was found in the regular expression.
*Action:   Ensure a valid range is being used.

Kindly provide your suggestions as to what is wrong that I am doing here.

Your range [XY] in the pattern is wrong, since:
X= \\FFFF is greater than Y= \\DBFF (I don't know what \\DBFF\\DFFF is supossed to do).

By analogy - this regular expression [ab] is right because a < b:

REGEXP_SUBSTR( 'some text', '[a-b]')

but this regular expression [ba] is wrong because b > a:

REGEXP_SUBSTR( 'some text', '[b-a]')

and you will get the same error in this case:

SELECT REGEXP_SUBSTR('This will be my first time visiting Seattle.','[b-a]' ) FROM dual;
ORA-12728: invalid range in regular expression

---------- EDIT ----------

But then why the query executes fine in 12c and gives an error in 11g?

I am trying on Oracle 12.1.0.2.0, and get the same error

SELECT * FROM V$VERSION;

SELECT REGEXP_SUBSTR('This will be my first time visiting Seattle. 😊',
       UNISTR('[\FFFF-\DBFF\DFFF]')) as str FROM dual;

BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production              0
PL/SQL Release 12.1.0.2.0 - Production                                                    0
CORE    12.1.0.2.0  Production                                                                  0
TNS for 64-bit Windows: Version 12.1.0.2.0 - Production                                   0
NLSRTL Version 12.1.0.2.0 - Production                                                    0


Error starting at line : 3 in command -
SELECT REGEXP_SUBSTR('This will be my first time visiting Seattle. 😊',
       UNISTR('[\FFFF-\DBFF\DFFF]')) as str FROM dual
Error report -
ORA-12728: invalid range in regular expression

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM