oracle
从第3个字符开始,截取6个字符
select substr('Hello SQL!', 3, 6) from dual -----llo SQ
查找子串在源串中的位置,从第5位开始,第二次出现
select instr('city_company_staff', '_', 5,2) from dual -------13
字符串连接,oracle的concat()函数只支持两个参数,不支持两个以上字符串的拼接,可以使用多个concat()函数嵌套使用
select 'hello'|| 'world' || '你好' from dual -----helloworld你好
select concat('hello', 'world' ) from dual -----helloworld
字符串长度,lengthb返回字符串的长度,单位是字节
select length('hello world你好') from dual ----13
select lengthb('hello world你好') from dual ----17
mysql:
从左边截取length
select left('city_company_staff',2) ----ci
从右边截取length
select right('city_company_staff',2) -----ff
从index开始,截取len长度,两个函数都支持
select substring('city_company_staff',2,5) ------ity_c
select substr('city_company_staff',2,5) ------ity_c
subdate(date,day)截取时间,时间减去后面的day
select subdate('2019-04-27',1) ------2019-04-26
查找子串在源串的位置, locate第三个参数为开始查找的位置
select locate('Hello','Hello World!') ---1
select position('Hello' in 'Hello World!') ---1
select locate('Hello' , 'Hello World!',1) ---1
字符串连接
select concat( 'hello', 'world' ,'www') -----helloworldwww
select concat_ws('-', 'hello', 'world' ,'www') -----hello-world-www
字符串长度,在mysql中length是计算字段的长度,一个汉字是算三个字符,一个数字或字母算一个字符
select length('hello world你好') ----17
select char_length('hello world你好') ----13
sqlserver:
从左边截取length
select left('SqlServer_2008',3) ----Sql
从右边截取length
select right('SqlServer_2008',3) -----008
从index开始,截取len长度
select substring('SqlServer_2008',3,6) ------lServe
查找子串在源串的位置, patindex()必须要用通配符,否则查询不到子字符串,charindex 第三个参数为开始查找的位置
select patindex('%Hello%','Hello World!') ---1
select charindex('Hello','Hello World!',1) ---1
字符串连接
select 'hello'+ 'world' -----helloworld
字符串长度
select len('hello world你好') ----13
select datalength('hello world你好') ----15
postgresql:
从index开始,截取len长度
select substring('hello world' from 3 for 5) ------llo w
select substring('hello world' , 3 , 5) -------llo w
查找子串在源串的位置
select position('h' in 'hello world') ------1
select strpos('hello world', 'h') ------1
字符串连接
select 'hello' || 'world' -----helloworld
字符串长度
select length('hello world') ----11
select char_length('hello world') ----11