Easy to use mysql string interception function

2011-09-01  来源:本站原创  分类:Database  人气:98 

MySQL string interception function: left (), right (), substring (), substring_index (). There are mid (), substr (). One, mid (), substr () is equivalent to substring () function, substring () function is very powerful and flexible.

1 String intercept: left (str, length)

mysql> select left('sqlstudy.com', 3);
+-------------------------+
| left('sqlstudy.com', 3) |
+-------------------------+
| sql                     |
+-------------------------+

2 String intercept: right (str, length)

mysql> select right('sqlstudy.com', 3);
+--------------------------+
| right('sqlstudy.com', 3) |
+--------------------------+
| com                      |
+--------------------------+

3 String intercept: substring (str, pos); substring (str, pos, len)

3.1 from the first four characters in the string position to take until the end.

mysql> select substring('sqlstudy.com', 4);
+------------------------------+
| substring('sqlstudy.com', 4) |
+------------------------------+
| study.com                    |
+------------------------------+

3.2 from the first four characters in the string position to take, only take 2 characters.

mysql> select substring('sqlstudy.com', 4, 2);
+---------------------------------+
| substring('sqlstudy.com', 4, 2) |
+---------------------------------+
| st                              |
+---------------------------------+

3.3 from the first four characters in the string position (last) began to take until the end.

mysql> select substring('sqlstudy.com', -4);
+-------------------------------+
| substring('sqlstudy.com', -4) |
+-------------------------------+
| .com                          |
+-------------------------------+

3.4 from the first four characters in the string position (bottom) start to take, just take the two characters.

mysql> select substring('sqlstudy.com', -4, 2);
+----------------------------------+
| substring('sqlstudy.com', -4, 2) |
+----------------------------------+
| .c                               |
+----------------------------------+

We note that the function substring (str, pos, len) in, pos can be negative, but the len can not take negative values.

4 String intercept: substring_index (str, delim, count)

4.1 second interception '.' Before all the characters.

mysql> select substring_index('www.sqlstudy.com.cn', '.', 2);
+------------------------------------------------+
| substring_index('www.sqlstudy.com.cn', '.', 2) |
+------------------------------------------------+
| www.sqlstudy                                   |
+------------------------------------------------+

4.2 second interception '.' (Bottom) after all the characters.

mysql> select substring_index('www.sqlstudy.com.cn', '.', -2);
+-------------------------------------------------+
| substring_index('www.sqlstudy.com.cn', '.', -2) |
+-------------------------------------------------+
| com.cn                                          |
+-------------------------------------------------+

4.3 If you can not find in the string delim parameter value specified, the entire string is returned

mysql> select substring_index('www.sqlstudy.com.cn', '.coc', 1);
+---------------------------------------------------+
| substring_index('www.sqlstudy.com.cn', '.coc', 1) |
+---------------------------------------------------+
| www.sqlstudy.com.cn                               |
+---------------------------------------------------+
相关文章
  • Easy to use mysql string interception function 2011-09-01

    MySQL string interception function: left (), right (), substring (), substring_index (). There are mid (), substr (). One, mid (), substr () is equivalent to substring () function, substring () function is very powerful and flexible. 1 String interce

  • String interception function (to avoid interception of half a utf8 encoded characters) 2010-10-27

    Velocity spread /** * Interception of string * @params $string: The target string :$sublen: Intercept length */ function CutStr($string, $sublen, $start = 0, $code = 'UTF-8') { if($code == 'UTF-8') { $pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\x

  • mysql string functions: string interception 2010-08-27

    MySQL string functions: string interception MySQL string interception function: left (), right (), substring (), substring_index (). There are mid (), substr (). One, mid (), substr () is equivalent to substring () function, substring () function is

  • MySQL string functions of the string intercept 2011-08-06

    MySQL string interception function: left (), right (), substring (), substring_index (). There are mid (), substr (). One, mid (), substr () is equivalent to substring () function, substring () function is very powerful and flexible. 1. String interc

  • MySQL string functions: String intercept 2011-08-06

    MySQL string interception function: left (), right (), substring (), substring_index (). There are mid (), substr (). One, mid (), substr () is equivalent to substring () function, substring () function is very powerful and flexible. 1 String interce

  • MySQL string functions intercept the string 2011-08-06

    MySQL string interception function: left (), right (), substring (), substring_index (). There are mid (), substr (). One, mid (), substr () is equivalent to substring () function, substring () function is very powerful and flexible. 1. String interc

  • Some classical string hash function 2010-08-19

    The article is excerpted from the transition http://www.cmykrgb123.cn/blog/string-hash-compare/ Commonly used string Hash functions ELFHash,APHash Etc., are very simple and efficient way . These functions use the Bitwise operation makes each characte

  • [Change] mysql string function 2010-06-01

    Transfer from: http://www.phpv.net/html/1443.html The location for the string operation, the first location is marked as 1. ASCII (str) Return str string of ASCII characters in the most left code values. If str is the empty string, return 0. If str i

  • mysql string function 2010-08-07

    The location for the string operation, the first location is marked as 1. ASCII(str) Return string str most left ASCII character code values. If str is an empty string, return 0. If str is NULL, return NULL. mysql> select ASCII('2'); -> 50 mysql>

  • Interception function string 2010-11-05

    C # language using a split () function, string interception: string str="1/2/3/444/3333/222/5555/"; string[] arr_str; arr_str=str.split('/'); for(int i=0;i<arr_str.length;i++) { Response.Write(strData[i]+"<br/>"); } The result

  • mysql the left, right, substr, instr string interception, the interception of decimal float 2010-12-04

    //------------------------------------------------ ----------------- select avg (stu_oder_percent) from tb_sch_collect Results: avg (stu_oder_percent): 60.60962 //------------------------------------------------ ----------------- select left (avg (st

  • mysql string operations 2011-06-22

    mysql-left, right, substr, instr string interception, the interception of decimal float 2007-07-29 14:10 mysql-left, right, substr, instr string interception, the interception of decimal float 2007-04-22 17:31 //--------------------------------------

  • js in js in English English string length string interception (change) 2010-03-30

    js in js in English English string length string interception (change) Keywords: javascript / interception Abstract: We use the procedures in the course of the text, frequently encountered problems in the English string, for example, we want a text e

  • utf encoded string interception of Chinese processing (to avoid interception and a half word / garbled case) 2010-04-08

    The following code to realize the Chinese utf-8 encoded string interception and interception in the string is longer than the length of time make up the ellipsis "..." (network code found to determine the conditions in some small bug, where do t

  • mysql default encryption function 2010-06-14

    mysql default encryption function rs1 = password (arg1) arg1 is expressly string, rs1 is 41 bytes long, 41 * 4 = 164 rs2 = MD5 (arg2) arg2 is expressly string, rs2 is 32 bytes long, 32 * 4 = 128

  • PHP common string partition function is then replaced and the comparison 2010-06-26

    PHP is commonly used in this paper is the distinction between matching function, mainly str_replace, str_ireplace, substr_replace, preg_replace, preg_match, preg_match_all, preg_quote, preg_split, ereg_replace, eregi_replace, preg_replace, str_split,

  • String concatenation function CONCAT () to compute the character length char_length () 2010-08-12

    String concatenation function CONCAT () SELECT TPASSWORD FROM tprovider_user WHERE char_length (TPASSWORD) <= 5 Calculating character length char_length () Sometimes, we need to be obtained in different fields of information to link together. Each da

  • mysql string handling 2010-09-06

    Position on the string in MY_SQL operation marked the first position are 1. ASCII (str) - returns the string str to the most left character of the ASCII code values. If str is the empty string, return 0. If str is NULL, return NULL. eg: select ASCII

  • mysql string functions <2> 2010-09-15

    SUBSTRING (str, pos) SUBSTRING (str FROM pos) String str from the start position pos return a substring. mysql> select SUBSTRING ('Quadratically', 5); -> 'Ratically' mysql> select SUBSTRING ('foobarbar' FROM 4); -> 'Barbar' This function is mu

  • PHP string interception 2010-10-14

    1. Interception GB2312 Chinese string <? Php / / Interception of Chinese string function mysubstr ($ str, $ start, $ len) { $ Tmpstr = ""; $ Strlen = $ start + $ len; for ($ i = 0; $ i <$ strlen; $ i + +) { if (ord (substr ($ str, $ i, 1))