replace
語法:
REPLACE ( string_expression , string_pattern , string_replacement )
參數:
- string_expression 要搜索的字符串表達式。string_expression 可以是字符或二進制數據類型。
- string_pattern 是要查找的子字符串。string_pattern 可以是字符或二進制數據類型。string_pattern 不能是空字符串 ('')。
- string_replacement 替換字符串。string_replacement 可以是字符或二進制數據類型。
返回類型:
- 如果其中的一個輸入參數數據類型為 nvarchar,則返回 nvarchar;否則 REPLACE 返回 varchar。
- 如果任何一個參數為 NULL,則返回 NULL。
上面都是官話,不好懂!翻成白話:REPLACE(String,from_str,to_str) 即:將String中所有出現的from_str替換為to_str。
substring_index
語法:
substring_index(str, delim, count)
參數:
- str:需要拆分的字符串;
- delim:分隔符,根據此字符來拆分字符串;
- count:當 count 為正數,取第 n 個分隔符之前的所有字符; 當 count 為負數,取倒數第 n 個分隔符之后的所有字符
select SUBSTRING_INDEX('mooc_100018252','_',-1); // 結果: 100018252
處理json字段
- 獲取指定json字符串中指定的屬性值,以下三種寫法等價:
json_extract(attributes_json,'$.DP') //獲取json中指定的值
attributes_json->'$.DP'
attributes_json->>'$.DP' //可以有兩個尖括號
- 去掉查詢結果中首尾的雙引號:
json_unquote()
如:
select json_unquote(json_extract(attributes_json,'$.DP')) as column_value from t_demand_point where instance_id=2146