mysql字符串截取命令

mysql字符串截取命令

 

1. substring_index

substring_index(str,delim,count)
 

[html]  www.aiwalls.com  

mysql> select substring_index('a-b-c-d','-',-1);  

+———————————–+  

| substring_index('a-b-c-d','-',-1) |  

+———————————–+  

| d                                 |   

+———————————–+  

1 row in set (0.00 sec)  

  

mysql> select substring_index('a-b-c-d','-',1);  

+———————————-+  

| substring_index('a-b-c-d','-',1) |  

+———————————-+  

| a                                |   

+———————————-+  

1 row in set (0.00 sec)  

  www.aiwalls.com 

2. SUBSTRING

SUBSTRING(str,pos,len)

SUBSTRING(str FROM pos FOR len)

SUBSTRING(str,pos)

SUBSTRING(str FROM pos)
 

[html] 

mysql> select substring((substring_index('a-b-c-d','-',2)),2);  

+————————————————-+  

| substring((substring_index('a-b-c-d','-',2)),2) |  

+————————————————-+  

| -b                                              |   

+————————————————-+  

1 row in set (0.01 sec)  
 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *