String
Generation
single quotes and escape
'''\''- 读取数据时,自动为其他语言转化为Escape
quote()SELECT quote(vchar_fld) FROM chap07;
Special characters (ASCII)
CHAR(): 将ASCII码转化为字符ASCII(): 将字符转化为ASCII码
字符串拼接
concat(string1,string2)
Manipulation
- 查看字符串长度
SELECT LENGTH($field_name) FROM $table_name;会自动移除CHAR()类型数据后的空格,因此对于CHAR类型的数据,其返回的也是实际字符的长度,而不是CHAR的规定长度。
- 寻找字符串的位置
POSITION('$want_find' IN $fieldname)ORINSTR($field_name,'$want_find')ORLOCATE('$want_find',$field_name,start_index)- 当查找不到时,返回0
- 索引从1开始!!!
字符串间比较
STRCMP($str_1, $str_2)- 返回值
- -1 $str_1 < $str_2
- 0 $str_1 = $str_2
- 1 $str_1 > $str_2
- 大小写不敏感('abcd' == 'ABCD')
- 返回值
LIKE和REGEXPSELECT $field_name LIKE $pattern当字符串符合pattern时返回1, 否则返回0
拼接字符
concat($str_1, $str_2)
插入和替换
INSERT($origin_str, $start_index, $number_of_replacement, $insert_str)- 当
$number_of_replacement为0时,就是简单的插入字符,相对REPLACE()更自由 - example:
SELECT INSERT('goodbye word',1,7,'hello') string;返回hello world
- 当
REPLACE($origin_str, $be_replaced_substr, $replace_str)- 会替换所有符合条件的
substr - example:
SELECT REPLACE('goodbye word goodbye','goodbye','hello') string;返回hello world hello
- 会替换所有符合条件的
提取substring
SUBSTRING($str, $start_index, $number_of_characters)等同于SUBSTR()