Operation | Syntax | Valid value | Return value | Example |
Append strings | op_add(str_1,str_2,...,str_n) | str_1: a string. str_2: a string. ... str_n: a string.
| The string after the append operation. | op_add(`col`,'hangzhou','dts') |
Format strings and append strings | str_format(format, value1, value2, value3, ...) | format: a string. Braces ({}) are used as placeholders. Example: "part1: {}, part2: {}". value1: an arbitrary value. value2: an arbitrary value.
| The string after the format operation. | str_format("part1: {}, part2: {}", `col1`, `col2`). In this example, if the value of col1 is ab and the value of col2 is 12, "part1: ab, part2: 12" is returned. |
Replace strings | str_replace(original, oldStr, newStr, count) | original: the original string. oldStr: the string to be replaced. newStr: the string after the replacement. count: an integer that indicates the maximum number of times that a string can be replaced. A value of -1 indicates that all oldStr is replaced with newStr.
| The string after the replace operation. | Example 1: str_replace(`name`, "a", 'b', 1). In this example, if the name is aba, bba is returned. Example 2: str_replace(`name`, "a", 'b', -1). In this example, if the name is aba, bbb is returned. |
Replace strings in the values of fields of all string types, such as the VARCHAR, TEXT, or CHAR type | tail_replace_string_field(search, replace, all) | search: the string to be replaced. replace: the string after the replacement. all: indicates whether to replace all matched strings. Only a value of true is supported. Note If you do not need to replace all matched strings, use the str_replace() function.
| The string after the replace operation. | tail_replace_string_field('\u000f','',true). In this example, all "\u000f" strings in the field values of the string type are replaced with spaces. |
Remove specific characters at the start and end of a string | str_strip(string_val, charSet) | | The string after the remove operation. | str_strip(`name`, 'ab'). In this example, if the name is axbzb, xbz is returned. |
Convert strings to lowercase letters | str_lower(value) | value: a column of the string type or a string constant. | The string after the convert operation. | str_lower(`str_col`) |
Convert strings to uppercase letters | str_upper(value) | value: a column of the string type or a string constant. | The string after the convert operation. | str_upper(`str_col`) |
Convert strings to numbers | cast_string_to_long(value) | value: a string. | The integer after the convert operation. | cast_string_to_long(`col`) |
Convert numbers to strings | cast_long_to_string(value) | value: an integer. | The string after the convert operation. | cast_long_to_string(`col`) |
Count strings | str_count(str,pattern) | | The number of times for which the substring appears. | str_count(`str_col`, 'abc'). In this example, if the value of str_col is zabcyabcz, 2 is returned. |
Query strings | str_find(str, pattern) | | The position in which the substring matches for the first time. If no match is found, -1 is returned. | str_find(`str_col`, 'abc'). In this example, if the value of str_col is xabcy, 1 is returned. |
Determine whether a string contains only letters | str_isalpha(str) | str: a column of the string type or a string constant. | true or false | str_isalpha(`str_col`) |
Determine whether a string contains only digits | str_isdigit(str) | | true or false | str_isdigit(`str_col`) |
Regular expression match | regex_match(str,regex) | | true or false | regex_match(__TB__,'user_\\d+') |
Mask part of a string with specific characters. This operation can be used for data masking. For example, mask the last four digits of a mobile phone number with four asterisks (*). | str_mask(str, start, end, maskStr) | str: a column of the string type or a string constant. start: an integer that indicates the start position of the masking. The minimum value is 0. end: an integer that indicates the end position of the masking. The maximum value is the length of the string minus 1. maskStr: a string. The length is 1. Example: #.
| The string whose part from start to end is masked with the specified characters. | str_mask(`phone`, 7, 10, '#') |
Truncate a string from the cond string to the last character | substring_after(str, cond) | | The string after the truncate operation. Note The return value does not contain the cond string. | substring_after(`col`, 'abc') |
Truncate a string from the first character to the cond string | substring_before(str, cond) | | The string after the truncate operation. Note The return value does not contain the cond string. | substring_before(`col`, 'efg') |
Truncate a string from the cond1 string to the cond2 string | substring_between(str, cond1, cond2) | | The string after the truncate operation. Note The return value does not contain the cond1 and cond2 strings. | substring_between(`col`, 'abc','efg') |
Determine whether the value is of the string type | is_string_value(value) | value: a string or a column name. | true or false | is_string_value(`col1`) |
Replace strings in the field values of the string type. The replacement starts from the end of the field values. | tail_replace_string_field(search, replace, all) | search: the string to be replaced. replace: the string after the replacement. all: indicates whether to replace all matched strings. Valid values: true and false. | The string after the replace operation. | In the following example, all "\u000f" strings in the field values of the string type are replaced with spaces: tail_replace_string_field('\u000f','',true) |
Query the value of a field in a MongoDB document | bson_value("field1","field2","field3", ...) | | The value of the corresponding field in the document. | e_set(`user_id`, bson_value("id")) e_set(`user_name`, bson_value("person","name"))
|