oracle 模糊查詢不區分大小寫 regexp_like

regexp_like(source_string ,pattern )

regexp_like(source_string ,pattern ,match_parameter )

  • source_string is a character expression that serves as the search value. It is commonly a character column and can be of any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.

  • pattern is the regular expression. It is usually a text literal and can be of any of the datatypes CHAR, VARCHAR2, NCHAR, or NVARCHAR2. It can contain up to 512 bytes. If the datatype of pattern is different from the datatype of source_string, Oracle converts pattern to the datatype of source_string. For a listing of the operators you can specify in pattern, please refer to Appendix C, " Oracle Regular Expression Support".

  • match_parameter is a text literal that lets you change the default matching behavior of the function. You can specify one or more of the following values for match_parameter:

    • 'i' specifies case-insensitive matching.

    • 'c' specifies case-sensitive matching.

    • 'n' allows the period (.), which is the match-any-character wildcard character, to match the newline character. If you omit this parameter, the period does not match the newline character.

    • 'm' treats the source string as multiple lines. Oracle interprets ^ and $ as the start and end, respectively, of any line anywhere in the source string, rather than only at the start or end of the entire source string. If you omit this parameter, Oracle treats the source string as a single line.

source_string 是要查詢匹配的字段

pattern 是正則表達式

match_parameter 匹配參數

‘i’不區分大小寫

‘c’區分大小寫


例如:

select A.CODE             AS arrivalStationCode,
       A.NAME             AS arrivalStationName,
       A.RAIL_BUREAU_NAME AS railReceiveBureau,
       B.RECEIVING_CODE   AS receiveUnitCode,
       B.RECEIVING_NAME   AS receiveUnitName,
       A.PROVINCE_NAME    AS province,
       B.RAILWAY_NAME     AS railwayName
  from B_PORT_STATION_INFO A, B_STATION_RECEIVING_STORAGE B
 where A.CODE = B.STATION_CODE(+) and regexp_like(A.MNEMONIC,'[N]','i')

但是如果在寫sql時使用佔位符
regexp_like(A.MNEMONIC,'[?]','i')
可能不會正確執行,程序可能將佔位符看做正則符號。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章