CHAR_MATCHCOUNT
函数声明:
- bigint char_matchcount(string str1, string str2)
用途:
用于计算 str1 中有多少个字符出现在 str2 中。
参数说明:
- str1,str2:String 类型,必须为有效的 UTF-8 字符串,如果对比中发现有无效字符则函数返回负值。
- bigint:返回值为 bigint 类型。任一输入为 NULL 返回 NULL。
示例如下:
- char_matchcount('abd','aabc') = 2
- -- str1中得两个字符串'a', 'b'在str2中出现过
CHR
函数声明:
- string chr(bigint ascii)
用途:
将给定 ASCII 码 ascii 转换成字符。
参数说明:
- ascii:Bigint 类型 ASCII 值,若输入为 string 类型或 double 类型或 decimal 类型会隐式转换到 bigint 类型后参与运算,其它类型抛异常。
- String:返回值为 String 类型。参数范围是 0~255,超过此范围会引发异常。输入值为 NULL 返回 NULL。
CONCAT
函数声明:
- string concat(string a, string b...)
用途:
返回值是将参数中的所有字符串连接在一起的结果。
参数说明:
- a,b 等为 String 类型,若输入为 bigint,decimal,double 或 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- String:返回值为 String 类型。如果没有参数或者某个参数为 NULL,结果均返回 NULL。
示例如下:
- concat('ab','c') = 'abc'
- concat() = NULL
- concat('a', null, 'b') = NULL
GET_JSON_OBJECT
函数声明:
- STRING GET_JSON_OBJECT(STRING json,STRING path)
用途:
在一个标准 json 字符串中,按照 path 抽取指定的字符串。
参数说明:
- json: String 类型,标准的 json 格式字符串。
- path:String 类型,用于描述在 json 中的 path,以 $ 开头。关于新实现中 json path 的说明,请参见:JsonPath,$ 表示根节点, “.”表示 child,”[number]”表示数组下标,对于数组,格式为 key[sub1][sub2][sub3]……, [*]返回整个数组,* 不支持转义。
- String:返回值为 String 类型。
注意:
- 如果 json 为空或者非法的 json 格式,返回 NULL;
- 如果 path 为空或者不合法(json 中不存在)返回 NULL;
- 如果 json 合法,path 也存在则返回对应字符串。
示例一:
- +----+
- json
- +----+
- {"store":
- {"fruit":[{"weight":8,"type":"apple"},{"weight":9,"type":"pear"}],
- "bicycle":{"price":19.95,"color":"red"}
- },
- "email":"amy@only_for_json_udf_test.net",
- "owner":"amy"
- }
通过以下查询,可以提取 json 对象中的信息:
- odps> SELECT get_json_object(src_json.json, '$.owner') FROM src_json;
- amy
- odps> SELECT get_json_object(src_json.json, '$.store.fruit\[0]') FROM src_json;
- {"weight":8,"type":"apple"}
- odps> SELECT get_json_object(src_json.json, '$.non_exist_key') FROM src_json;
- NULL
示例二:
- get_json_object('{"array":[[aaaa,1111],[bbbb,2222],[cccc,3333]]}','$.array[1].[1]') = "2222"
- get_json_object('{"aaa":"bbb","ccc":{"ddd":"eee","fff":"ggg","hhh":["h0","h1","h2"]},"iii":"jjj"}','$.ccc.hhh[*]') = "["h0","h1","h2"]"
- get_json_object('{"aaa":"bbb","ccc":{"ddd":"eee","fff":"ggg","hhh":["h0","h1","h2"]},"iii":"jjj"}','$.ccc.hhh[1]') = "h1"
INSTR
函数声明:
- bigint instr(string str1, string str2[, bigint start_position[, bigint nth_appearance]])
用途:
计算子串 str2 在字符串 str1 中的位置。
参数说明:
- str1:String 类型,搜索的字符串,若输入为 bigint,decimal,double 或 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- str2:String 类型,要搜索的子串,若输入为 bigint,decimal,double 或 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- start_position:bigint 类型,其它类型会抛异常,表示从 str1 的第几个字符开始搜索,默认起始位置是第一个字符位置 1。
- nth_appearance:bigint 类型,大于 0,表示子串在字符串中的第 nth_appearance 次匹配的位置,如果 nth_appearance 为其它类型或小于等于 0 会抛异常。
- bigint:返回值为 bigint 类型。
注意:
- 如果在 str1 中未找到 str2,返回 0;
- 任一输入参数为 NULL 返回 NULL;
- 如果 str2 为空串时总是能匹配成功,因此 instr(‘abc’, ‘’) 会返回 1。
示例如下:
- instr('Tech on the net', 'e') = 2
- instr('Tech on the net', 'e', 1, 1) = 2
- instr('Tech on the net', 'e', 1, 2) = 11
- instr('Tech on the net', 'e', 1, 3) = 14
IS_ENCODING
函数声明:
- boolean is_encoding(string str, string from_encoding, string to_encoding)
用途:
判断输入字符串 str 是否可以从指定的一个字符集 from_encoding 转为另一个字符集to_encoding。可用于判断输入是否为”乱码”,通常的用法是将 from_encoding 设为 “utf-8”,to_encoding设为 “gbk”。
参数说明:
- str:String 类型,输入为 NULL 返回 NULL。空字符串则可以被认为属于任何字符集。
- from_encoding,to_encoding:String 类型,源及目标字符集。输入为 NULL 返回 NULL。
- boolean:返回值为 boolean 类型,如果 str 能够成功转换,则返回 true,否则返回 false。
示例如下:
- is_encoding('测试', 'utf-8', 'gbk') = true
- is_encoding('測試', 'utf-8', 'gbk') = true
- -- gbk字库中有这两个繁体字
- is_encoding('測試', 'utf-8', 'gb2312') = false
- -- gb2312库中不包括这两个字
KEYVALUE
函数声明:
- KEYVALUE(STRING srcStr,STRING split1,STRING split2, STRING key)
- KEYVALUE(STRING srcStr,STRING key) //split1 = ";",split2 = ":"
用途:
将 srcStr(源字符串)按 split1 分成 “key-value” 对,按 split2 将 key-value 对分开,返回 “key” 所对应的 value。
参数说明:
- srcStr 输入待拆分的字符串。
- key:string 类型。源字符串按照 split1 和 split2 拆分后,根据该 key 值的指定,返回其对应的 value。
- split1,split2:用来作为分隔符的字符串,按照指定的这两个分隔符拆分源字符串。如果表达式中没有指定这两项,默认 split1 为’;’, split2 为’:’。当某个被 split1 拆分后的字符串中有多个 split2 时,返回结果未定义。
- 返回值: String 类型;
- Split1 或 split2 为 NULL 时,返回 NULL;
- srcStr,key 为 NULL 或者没有匹配的 key 时,返回NULL;
- 如果有多个 key-value 匹配,返回第一个匹配上的 key 对应的 value。
示例如下:
- keyvalue('0:1\;1:2', 1) = '2'
- -源字符串为“0:1\;1:2”,因为没有指定split1和split2,默认split1为";",split2为“:”。经过split1拆分后,key-value对为:
- 0:1\,1:2
- 经过split2拆分后变成:
- 0 1/
- 1 2
- 返回key为1所对应的value值,为2。
- keyvalue("\;decreaseStore:1\;xcard:1\;isB2C:1\;tf:21910\;cart:1\;shipping:2\;pf:0\;market:shoes\;instPayAmount:0\;", "\;",":","tf") = "21910"
- -源字符串为“\;decreaseStore:1\;xcard:1\;isB2C:1\;tf:21910\;cart:1\;shipping:2\;pf:0\;market:shoes\;instPayAmount:0\;”,按照 split1“\;”拆分后,得出的key-value对为:
- decreaseStore:1,xcard:1,isB2C:1,tf:21910,cart:1,shipping:2,pf:0,market:shoes,instPayAmount:0
- 按照split2":"拆分后变成:
- decreaseStore 1
- xcard 1
- isB2C 1
- tf 21910
- cart 1
- shipping 2
- pf 0
- market shoes
- instPayAmount 0
- key值为“tf”,返回其对应的value:21910。
LENGTH
函数声明:
- bigint length(string str)
用途:
返回字符串 str 的长度。
参数说明:
- str:String 类型,若输入为 bigint,double,decimal 或 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- bigint:返回值为 bigint 类型。若 str 是 NULL 返回 NULL。如果 str 非 UTF-8 编码格式,返回 -1。
示例如下:
- length('hi! 中国') = 6
LENGTHB
函数声明:
- bigint lengthb(string str)
用途:
返回字符串 str 的以字节为单位的长度。
参数说明:
- str:String 类型,若输入为 bigint,double,decimal 或者 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- bigint:返回值为 bigint 类型。若 str 是 NULL 返回 NULL。
示例如下:
- lengthb('hi! 中国') = 10
MD5
函数声明:
- string md5(string value)
用途:
计算输入字符串 value 的 md5 值。
参数说明:
- value:String 类型,如果输入类型是 bigint,double,decimal 或者 datetime 会隐式转换成 string 类型参与运算,其它类型报异常。输入为 NULL,返回 NULL。
- String:返回值为 String 类型。
REGEXP_EXTRACT
函数声明:
- string regexp_extract(string source, string pattern[, bigint occurrence])
用途:
将字符串 source 按照 pattern 正则表达式的规则拆分,返回第 occurrence 个 group 的字符。
参数说明:
- source:String 类型,待搜索的字符串。
- pattern:String 类型常量,pattern 为空串时抛异常,pattern 中如果没有指定 group,抛异常。
- occurrence:Bigint 类型常量,必须 >=0,其它类型或小于 0 时抛异常,不指定时默认为 1,表示返回第一个 group。若 occurrence = 0,返回满足整个 pattern 的子串。
- String:返回值为 String 类型,任一输入为 NULL 返回 NULL。
示例如下:
- regexp_extract('foothebar', 'foo(.*?)(bar)', 1) = the
- regexp_extract('foothebar', 'foo(.*?)(bar)', 2) = bar
- regexp_extract('foothebar', 'foo(.*?)(bar)', 0) = foothebar
- regexp_extract('8d99d8', '8d(\\d+)d8') = 99
- -- 如果是在MaxCompute客户端上提交正则计算的SQL,需要使用两个"\"作为转移字符
- regexp_extract('foothebar', 'foothebar')
- -- 异常返回,pattern中没有指定group
REGEXP_INSTR
函数声明:
- bigint regexp_instr(string source, string pattern[,
- bigint start_position[, bigint nth_occurrence[, bigint return_option]])
用途:
返回字符串 source 从 start_position 开始,和 pattern 第 n 次(nth_occurrence)匹配的子串的起始/结束位置。任一输入参数为 NULL 时返回 NULL。
参数说明:
- source:String 类型,待搜索的字符串。
- pattern:String 类型常量,pattern 为空串时抛异常。
- start_position:Bigint 类型常量,搜索的开始位置。不指定时默认值为 1,其它类型或小于等于 0 的值会抛异常。
- nth_occurrence:Bigint 类型常量,不指定时默认值为1,表示搜索第一次出现的位置。小于等于0或者其它类型抛异常。
- return_option:Bigint 类型常量,值为 0 或 1,其它类型或不允许的值会抛异常。0 表示返回匹配的开始位置,1 表示返回匹配的结束位置。
- bigint:返回值为 bigint 类型。return_option 指定的类型返回匹配的子串在 source 中的开始或结束位置。
示例如下:
- regexp_instr("i love www.taobao.com", "o[[:alpha:]]{1}", 3, 2) = 14
REGEXP_REPLACE
函数声明:
- string regexp_replace(string source, string pattern, string replace_string[, bigint occurrence])
用途:
将 source 字符串中第 occurrence 次匹配 pattern 的子串替换成指定字符串 replace_string 后返回。
参数说明:
- source:String 类型,要替换的字符串。
- pattern:String 类型常量,要匹配的模式,pattern 为空串时抛异常。
- replace_string:String 类型,将匹配的 pattern 替换成的字符串。
- occurrence:Bigint 类型常量,必须大于等于 0,表示将第几次匹配替换成 replace_string,为 0 时表示替换掉所有的匹配子串。其它类型或小于 0 抛异常。可缺省,默认值为 0。
- String:返回值为String 类型,当引用不存在的组时,不进行替换。当输入 source,pattern,occurrence 参数为 NULL 时返回NULL,若 replace_string 为 NULL 且 pattern 有匹配,返回 NULL,replace_string 为 NULL但 pattern 不匹配,则返回原串。
备注:
示例如下:
- regexp_replace("123.456.7890", "([[:digit:]]{3})\\.([[:digit:]]{3})\\.([[:digit:]]{4})",
- "(\\1)\\2-\\3", 0) = "(123)456-7890"
- regexp_replace("abcd", "(.)", "\\1 ", 0) = "a b c d "
- regexp_replace("abcd", "(.)", "\\1 ", 1) = "a bcd"
- regexp_replace("abcd", "(.)", "\\2", 1) = "abcd"
- -- 因为pattern中只定义了一个组,引用的第二个组不存在,
- -- 请避免这样使用,引用不存在的组的结果未定义。
- regexp_replace("abcd", "(.*)(.)$", "\\2", 0) = "d"
- regexp_replace("abcd", "a", "\\1", 0) = "bcd"
- -- 因为在pattern中没有组的定义,所以\1引用了不存在的组,
- -- 请避免这样使用,引用不存在的组的结果未定义。
REGEXP_SUBSTR
函数声明:
- string regexp_substr(string source, string pattern[, bigint start_position[, bigint nth_occurrence]])
用途:
从 start_position 位置开始,source 中第 nth_occurrence 次匹配指定模式 pattern 的子串。
参数说明:
- source:String 类型,搜索的字符串。
- pattern:String 类型常量,要匹配的模型,pattern 为空串时抛异常。
- start_position:Bigint 常量,必须大于 0。其它类型或小于等于 0 时抛异常,不指定时默认为 1,表示从 source 的第一个字符开始匹配。不指定时默认为 1,表示从 source 的第一个字符开始匹配。
- nth_occurrence:Bigint 常量,必须大于 0,其它类型或小于等于 0 时抛异常。不指定时默认为 1,表示返回第一次匹配的子串。不指定时默认为 1,表示返回第一次匹配的子串。
- String:返回值为 String 类型。任一输入参数为 NULL 返回 NULL。没有匹配时返回 NULL。
示例如下:
- regexp_substr ("I love aliyun very much", "a[[:alpha:]]{5}") = "aliyun"
- regexp_substr('I have 2 apples and 100 bucks!', '[[:blank:]][[:alnum:]]*', 1, 1) = " have"
- regexp_substr('I have 2 apples and 100 bucks!', '[[:blank:]][[:alnum:]]*', 1, 2) = " 2"
REGEXP_COUNT
函数声明:
- bigint regexp_count(string source, string pattern[, bigint start_position])
用途:
计算 source 中从 start_position 开始,匹配指定模式 pattern 的子串的次数。
参数说明:
- source:String 类型,搜索的字符串,其它类型报异常。
- pattern:String 类型常量,要匹配的模型,pattern 为空串时抛异常,其它类型报异常。
- start_position:Bigint 类型常量,必须大于 0。其它类型或小于等于 0 时抛异常,不指定时默认为 1,表示从 source 的第一个字符开始匹配。
- bigint:返回值为 bigint 类型。没有匹配时返回 0。任一输入参数为 NULL 返回 NULL。
示例如下:
- regexp_count('abababc', 'a.c') = 1
- regexp_count('abcde', '[[:alpha:]]{2}', 3) = 1
SPLIT_PART
函数声明:
- string split_part(string str, string separator, bigint start[, bigint end])
用途:
依照分隔符 separator 拆分字符串 str,返回从第 start 部分到第 end 部分的子串(闭区间)。
参数说明:
- Str:String 类型,要拆分的字符串。如果是 bigint,double,decimal 或者 datetime 类型会隐式转换到 string 类型后参加运算,其它类型报异常。
- Separator:String 类型常量,拆分用的分隔符,可以是一个字符,也可以是一个字符串,其它类型会引发异常。
- start:Bigint 类型常量,必须大于 0。非常量或其它类型抛异常。返回段的开始编号(从1开始),如果没有指定 end,则返回 start 指定的段。
- end:Bigint 类型常量,大于等于 start,否则抛异常。返回段的截止编号,非常量或其他类型会引发异常。可省略,缺省时表示最后一部分。
- String:返回值为 String 类型。若任意参数为 NULL,返回 NULL;若 separator 为空串,返回原字符串 str。
备注:
- 如果 separator 不存在于 str 中,且 start 指定为 1,返回整个 str。若输入为空串,输出为空串。
- 如果 start 的值大于切分后实际的分段数,例如:字符串拆分完有 6 个片段,但 start 大于 6,返回空串””。
- 若 end 大于片段个数,按片段个数处理。
示例如下:
- split_part('a,b,c,d', ',', 1) = 'a'
- split_part('a,b,c,d', ',', 1, 2) = 'a,b'
- split_part('a,b,c,d', ',', 10) = ''
SUBSTR
函数声明:
- string substr(string str, bigint start_position[, bigint length])
用途:
返回字符串 str从start_position 开始往后数,长度为 length 的子串。
参数说明:
- str:String 类型,若输入为 bigint,decimal,double 或者 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- start_position:Bigint 类型,起始位置为 1。当 start_position 为负数时表示开始位置是从字符串的结尾往前倒数,最后一个字符是 -1,往前数依次就是 -2,-3…,其它类型抛异常。
- length:Bigint 类型,大于 0,其它类型或小于等于 0 抛异常。子串的长度。
- String:返回值为 String 类型。若任一输入为 NULL,返回 NULL。
备注 :
- 当 length 被省略时,返回到 str 结尾的子串。
示例如下:
- substr("abc", 2) = "bc"
- substr("abc", 2, 1) = "b"
- substr("abc",-2,2)="bc"
- substr("abc",-3)="abc"
TOLOWER
函数声明:
- string tolower(string source)
用途:
输出英文字符串 source 对应的小写字符串。
参数说明:
- source:String 类型,若输入为 bigint,double,decimal 或者 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- String:返回值为 String 类型。输入为 NULL 时返回 NULL。
示例如下:
- tolower("aBcd") = "abcd"
- tolower("哈哈Cd") = "哈哈cd"
TOUPPER
函数声明:
- string toupper(string source)
用途:
输出英文字符 source 串对应的大写字符串。
参数说明:
- source:String 类型,若输入为 bigint,double,decimal 或者 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- String:返回值为 String 类型。输入为 NULL 时返回 NULL。
示例如下:
- toupper("aBcd") = "ABCD"
- toupper("哈哈Cd") = "哈哈CD"
TO_CHAR
函数声明:
- string to_char(boolean value)
- string to_char(bigint value)
- string to_char(double value)
- string to_char(decimal value)
用途:
将 Boolean 类型、bigint 类型、decimal 类型或者 double 类型转为对应的 string 类型表示。
参数说明:
- value:可以接受 boolean 类型、bigint 类型、decimal 类型或者 double 类型输入,其它类型抛异常。对 datetime 类型的格式化输出请参考另一同名函数 TO_CHAR 。
- String:返回值为 String 类型。如果输入为 NULL,返回 NULL。
示例如下:
- to_char(123) = '123'
- to_char(true) = 'TRUE'
- to_char(1.23) = '1.23'
- to_char(null) = NULL
TRIM
函数声明:
- string trim(string str)
用途:
将输入字符串 str 去除左右空格。
参数说明:
- str:String 类型,若输入为 bigint,decimal,double 或者 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- String:返回值为 String 类型。输入为 NULL 时返回 NULL。
LTRIM
函数声明:
- string ltrim(string str)
用途:
将输入的字符串 str 去除左边空格。
参数说明:
- str:String 类型,若输入为 bigint,decimal,double 或者 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- String:返回值为 String 类型。输入为 NULL 时返回 NULL。
示例如下:
- select ltrim(' abc ') from dual;
- 返回:
- +-----+
- | _c0 |
- +-----+
- | abc |
- +-----+
RTRIM
函数声明:
- string rtrim(string str)
用途:
将输入的字符串 str 去除右边空格。
参数说明:
- str:String 类型,若输入为 bigint,decimal,double 或者 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- String:返回值为 String 类型。输入为 NULL 时返回 NULL。
示例如下:
- select rtrim('a abc ') from dual;
- 返回:
- +-----+
- | _c0 |
- +-----+
- | a abc |
- +-----+
REVERSE
函数申明:
- STRING REVERSE(string str)
用途:
返回倒序字符串。
参数说明:
- str:String 类型,若输入为 bigint,double,decimal 或 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- String:返回值为 String 类型。输入为 NULL 时返回 NULL。
示例如下:
- select reverse('abcedfg') from dual;
- 返回:
- +-----+
- | _c0 |
- +-----+
- | gfdecba |
- +-----+
SPACE
函数声明:
- STRING SPACE(bigint n)
用途:
空格字符串函数,返回长度为 n 的字符串。
参数说明:
- n: bigint 类型。长度不超过 2M。如果为空,则抛异常。
- String:返回值为 String 类型。
示例如下:
- select length(space(10)) from dual; ----返回10。
- select space(400000000000) from dual; ----报错,长度超过2M。
REPEAT
函数声明:
- STRING REPEAT(string str, bigint n)
用途:
返回重复 n 次后的 str 字符串。
参数说明:
- str:String 类型,若输入为 bigint,double,decimal 或 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- n: Bigint 类型。长度不超过 2M。如果为空,则抛异常。
- String:返回值为 String 类型。
示例如下:
- select repeat('abc',5) from lxw_dual;
- 返回:abcabcabcabcabc
ASCII
函数声明:
- Bigint ASCII(string str)
用途:
返回字符串 str 第一个字符的 ascii 码。
参数说明:
- str:String 类型,若输入为 bigint,double,decimal 或 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
- Bigint:返回值为 Bigint 类型。
示例如下:
- select ascii('abcde') from dual;
- 返回值:97
MaxCompute2.0扩展支持的字符串函数如下:
CONCAT_WS
函数声明:
- string concat_ws(string SEP, string a, string b...)
用途:返回值是将参数中的所有字符串安装指定的分隔符连接在一起的结果。
参数说明:
- SEP:string类型的分隔符,若不指定,返回的值异常。
- a/b等:String 类型,若输入为 bigint,decimal,double 或 datetime 类型会隐式转换为 string 后参与运算,其它类型报异常。
返回值:为 String 类型。如果没有参数或者某个参数为 NULL,结果均返回 NULL。
示例如下:
- concat_ws(':','name','hanmeimei')='name:hanmeimei'
- concat_ws(':','avg',null,'34')=null
LPAD
函数声明:
- string lpad(string a, int len, string b)
用途:用b字符串将a字符串向左补足到len位。
需在使用该函数的sql语句前加语句set odps.sql.type.system.odps2=true,否则会报错。
参数说明:
- len:int整型,
- a/b等:String 类型。
返回值:为 String 类型。若len小于a的位数,则返回a从左开始截取len位字符;若len为0则返回空。
示例如下:
- lpad('abcdefgh',10,'12')='12abcdefgh'
- lpad('abcdefgh',5,'12')='abcde'
- lpad('abcdefgh',0,'12')返回空
RPAD
函数声明:
- string rpad(string a, int len, string b)
用途:用b字符串将a字符串向右补足到len位。
需在使用该函数的sql语句前加语句set odps.sql.type.system.odps2=true,否则会报错。
参数说明:
- len:int整型,
- a/b等:String 类型。
返回值:为 String 类型。若len小于a的位数,则返回a从左开始截取len位字符;若len为0则返回空。
示例如下:
- rpad('abcdefgh',10,'12')='abcdefgh12'
- rpad('abcdefgh',5,'12')='abcde'
- rpad('abcdefgh',0,'12')返回空
REPLACE
函数声明:
- string replace(string a, string OLD, string NEW)
用途:用NEW字符串替换a字符串中与OLD字符串完全重合的部分并返回a。
参数说明:参数都为string类型。
返回值:为 String 类型,若某个参数为null,则返回null。
示例如下:
- replace('ababab','abab','12')='12ab'
- replace('ababab','cdf','123')='ababab'
- replace('123abab456ab',null,'abab')=null
SOUNDEX
函数声明:
- string soundex(string a)
用途:将普通字符串转换成soundex字符串。
参数说明:为string类型。
返回值:为 String 类型,若输入为null,则返回null。
示例如下:
- soundex('hello')='H400'
SUBSTRING_INDEX
函数声明:
- string substring_index(string a, string SEP, int count))
用途:截取字符串a第count分隔符之前的字符串,如count为正则从左边开始截取,如果为负则从右边开始截取。
参数说明:a/sep为string类型,count为int类型。
返回值:返回 String 类型,若输入为null,则返回null。
示例如下:
- substring_index('https://help.aliyun.com', '.', 2)='https://help.aliyun'
- substring_index('https://help.aliyun.com', '.', -2)='aliyun.com'
- substring_index('https://help.aliyun.com', null, 2)=null