REGEXP_SUBSTR函数格式如下:
REGEXP_SUBSTR(source_char, pattern
[, position
[, occurrence
[, match_param
[, subexpr
]
]
]
]
)
-
source_charis a character expression that serves as the search value. It is commonly a character column and can be of any of the data typesCHAR,VARCHAR2,NCHAR,NVARCHAR2,CLOB, orNCLOB. -
patternis the regular expression. It is usually a text literal and can be of any of the data typesCHAR,VARCHAR2,NCHAR, orNVARCHAR2. It can contain up to 512 bytes. If the data type ofpatternis different from the data type ofsource_char, then Oracle Database convertspatternto the data type ofsource_char. For a listing of the operators you can specify inpattern, refer to Appendix D, "Oracle Regular Expression Support". -
positionis a positive integer indicating the character ofsource_charwhere Oracle should begin the search. The default is 1, meaning that Oracle begins the search at the first character ofsource_char. -
occurrenceis a positive integer indicating which occurrence ofpatterninsource_charOracle should search for. The default is 1, meaning that Oracle searches for the first occurrence ofpattern.If
occurrenceis greater than 1, then the database searches for the second occurrence beginning with the first character following the first occurrence ofpattern, and so forth. This behavior is different from theSUBSTRfunction, which begins its search for the second occurrence at the second character of the first occurrence. -
match_parameteris a text literal that lets you change the default matching behavior of the function. The behavior of this parameter is the same for this function as forREGEXP_COUNT. Refer to REGEXP_COUNT for detailed information. -
For a
patternwith subexpressions,subexpris a nonnegative integer from 0 to 9 indicating which subexpression inpatternis to be returned by the function. This parameter has the same semantics that it has for theREGEXP_INSTRfunction. Refer to REGEXP_INSTR for more information.
with t as (
select * from file_test a
where a.tpid = '110'
and instr(a.sqid, ',') > 0
)
select regexp_substr(t.sqid, '[^,]+', 1, level) sqid,t.filename,t.updatetime from t
connect by prior rowid = rowid
and prior dbms_random.value is not null
and level <= regexp_count(t.sqid, '[^,]+')
PRIOR
In a hierarchical query, one expression in the CONNECT BY condition must be qualified by the PRIOR operator. If the CONNECT BY condition is compound, then only one condition requires the PRIORoperator, although you can have multiple PRIOR conditions. PRIOR evaluates the immediately following expression for the parent row of the current row in a hierarchical query.
DBMS_RANDOM.VALUE Functions
The basic function gets a random number, greater than or equal to 0 and less than 1, with 38 digits to the right of the decimal (38-digit precision). Alternatively, you can get a random Oracle number x, where x is greater than or equal to low and less than high.
以此来防止出现循环。
博客围绕Oracle数据库展开,介绍了正则表达式相关参数,如搜索值、正则表达式、起始搜索位置等,还给出了相关查询示例。此外,提到了分层查询中PRIOR操作符的使用,以及DBMS_RANDOM.VALUE函数获取随机数的功能。
303

被折叠的 条评论
为什么被折叠?



