presto中常见字符串函数操作

您所在的位置:网站首页 sql替换多个字符串怎么操作 presto中常见字符串函数操作

presto中常见字符串函数操作

2024-07-08 01:17| 来源: 网络整理| 查看: 265

1、字符串截取substr

presto语法:

substr(string, start, length) → varchar   如: select substr('1599319787151',1,10) 

substr(string, start) → varchar        如: select substr('1599319787151',1) 而hive中:substr和substring都可以使用

2、字符串替换regexp_replace

presto语法:

regexp_replace(string, pattern, replacement) → varchar

 如:select  regexp_replace('{\\"over\\":\\"0\\",\\"seckill\\":\\"0\\"}','\\','')

3、字符串首次出现位置position(下标从1开始的)

presto语法:

position(substring IN string) → bigint  如:select position('aa' in '15993aa1978715aa1') 

而hive中:select INSTR('15993aa1978715aa1','aa')  

4、字符串连接concat

presto语法:concat(string1, ..., stringN) → varchar  如:select  concat('kk','rrr')

而hive中除了concat,还有concat_ws按分隔符分割,如:select concat_ws("-","iii","rrr","kkk")

5、字符串分割split

presto语法:

split(string, delimiter) -> array(varchar)  如:SELECT split('a,b,c,d',',')  得到:[a, b, c, d]

split_part(string, delimiter, index) → varchar 如:SELECT split_part('a,b,c,d',',',2)  得到:b  

String Functions and Operators — Presto 0.277 Documentationhttps://prestodb.io/docs/current/functions/string.html

Regular Expression Functions — Presto 0.277 Documentationhttps://prestodb.io/docs/current/functions/regexp.html?highlight=regexp_replace#id3 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3