mysql the substring () function characters taken

substring (parameter 1, parameter 2, parameter 3), wherein the three parameters represent: 1 represents the need to intercept parameter string parameter 2 from that represents the start position of the string taken (subscript string starting from 1), the parameters 3 shows the number of bits to be intercepted, if you do not write, represents the beginning of the rest of the interception from the location specified parameters 2 all characters.
E.g:

  1. select substring ( "jason", 1,2 );
    results: ja
  2. select substring ( "jason", 1 );
    results: jason
  3. select substring ( "jason", 2 );
    results: ason
    These are parameters for the case of a positive number. Circumstances then when parameter 2 is negative it? Note that the argument is a 3-digit intercepted, it can not be negative, if negative, the query result will be null.

The following is the case when parameter 2 is negative

  1. select substring ( "jason", - 1);
    Results as follows: n
    taken Thought: Starting from the forward end of the string taken.
  2. select substring ( "jason", - 3);
    results: son
  3. select substring ( "jason", - 3,1);
    the result is: s
    interception thought: if there is 3 digits parameter specifies the need to intercept, then from left to right beginning from the first interception is to end, rather than from Last to first start.
  4. select substring ( "jason", - 3,2);
    the result is: so
  5. select substring ( "jason", - 3, -1);
    the result is: null
  6. select substring ( "jason", - 3,0);
    the result is: null

Guess you like

Origin www.cnblogs.com/jasonboren/p/11096187.html