hive中 regexp_replace的用法,替換特殊字符問題


數據倉庫中有的字段不合格,有特殊字符,比如換行符。

poi_name
\n19013
\n12013

怎么把換行符替換掉呢?

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-StringOperators

regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT)

Returns the string resulting from replacing all substrings in INITIAL_STRING that match the java regular expression syntax defined in PATTERN with instances of REPLACEMENT. For example, regexp_replace("foobar", "oo|ar", "") returns 'fb.' Note that some care is necessary in using predefined character classes: using '\s' as the second argument will match the letter s; '\s' is necessary to match whitespace, etc.

官網說用兩個反斜杠代替一個,即一個反斜杠用來轉義。

實踐了一下,不行,得4個

select regexp_replace(poi_name,'\\\\n','') 

poi_name
19013
12013


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM