oracle根据分隔符一行转多行

REGEXP_SUBSTR函数格式如下:
REGEXP_SUBSTR(source_char, pattern
              [, position
                 [, occurrence
                    [, match_param
                       [, subexpr
                       ]
                    ]
                 ]
              ]
             )
  • source_char is a character expression that serves as the search value. It is commonly a character column and can be of any of the data types CHARVARCHAR2NCHARNVARCHAR2CLOB, or NCLOB.

  • pattern is the regular expression. It is usually a text literal and can be of any of the data types CHARVARCHAR2NCHAR, or NVARCHAR2. It can contain up to 512 bytes. If the data type of pattern is different from the data type of source_char, then Oracle Database converts pattern to the data type of source_char. For a listing of the operators you can specify in pattern, refer to Appendix D, "Oracle Regular Expression Support".

  • position is a positive integer indicating the character of source_char where Oracle should begin the search. The default is 1, meaning that Oracle begins the search at the first character of source_char.

  • occurrence is a positive integer indicating which occurrence of pattern in source_char Oracle should search for. The default is 1, meaning that Oracle searches for the first occurrence of pattern.

    If occurrence is greater than 1, then the database searches for the second occurrence beginning with the first character following the first occurrence of pattern, and so forth. This behavior is different from the SUBSTR function, which begins its search for the second occurrence at the second character of the first occurrence.

  • match_parameter is 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 for REGEXP_COUNT. Refer to REGEXP_COUNT for detailed information.

  • For a pattern with subexpressions, subexpr is a nonnegative integer from 0 to 9 indicating which subexpression in pattern is to be returned by the function. This parameter has the same semantics that it has for the REGEXP_INSTR function. 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)