SUBSTRING (expression, start, length) returns a part of the character, binary, text, or image expression. The expression parameter is a string, binary string, text, image, column, or an expression that contains columns. Do not use expressions that contain aggregate functions. Start is an integer that indicates the start position of the substring.
SUBSTRING (expression, start, length) returns a part of the character, binary, text, or image expression. The expression parameter is a string, binary string, text, image, column, or an expression that contains columns. Do not use expressions that contain aggregate functions. Start is an integer that indicates the start position of the substring.
Substring (expression, start, length) returns a part of the character, binary, text, or image expression.
Parameters
Expression
Is a string, binary string, text, image, column, or expression that contains a column. Do not use expressions that contain aggregate functions.
Start
It is an integer that refers to the starting position of the stator string.
Length
It is an integer that refers to the length of the substring (the number of characters to return or the number of bytes ).
Use pubs
Select pub_id, substring (logo, 1, 10) as logo,
Substring (pr_info, 1, 10) as pr_info
From pub_info
Where pub_id = '20140901'
If exists (select table_name from information_schema.tables
Where table_name = 'npub _ info ')
Drop table npub_info
Go
View instances
Method 2: (similar to method 1)
Declare @ s1 varchar (100)
Select @ s1 = 'HTTP: // www.111cn.net'
Select substring (@ s1, patindex ('% www %', @ s1) + 1, len (@ s1 ))
-- This can also be written as follows: select substring (@ s1, patindex ('% // %', @ s1) + 2, len (@ s1 ))
Left (character_expression, integer_expression) returns the specified number of characters starting from the left of the string.
Parameters
Character_expression
Character or binary data expression. Character_expression can be a constant, variable, or column. Character_expression must be a data type that can be implicitly converted to varchar. Otherwise, use the cast function to digitally convert character_expression.
Integer_expression
Is a positive integer. If integer_expression is negative, an empty string is returned.
Return type
Varchar
Right (character_expression, integer_expression) returns the number of integer_expression characters specified from the right.
Parameters
Character_expression
An expression composed of character data. Character_expression can be a constant, variable, or a column of character or binary data.
Integer_expression
Is the starting position, expressed in a positive integer. If integer_expression is negative, an error is returned.
Return type
Varchar
Next let's take a look at
Mysql string truncation functions: left (), right (), substring (), substring_index (). There are also mid () and substr (). Here, mid () and substr () are equivalent to substring () functions. substring () functions are very powerful and flexible.
1. String truncation: left (str, length)
Mysql> select left ('sqlstudy. com', 3 );
+ ------------------------- +
| Left ('sqlstudy. com', 3) |
+ ------------------------- +
| SQL |
+ ------------------------- +
2. String truncation: right (str, length)
Mysql> select right ('sqlstudy. com', 3 );
Select reverse (left (reverse ('192. 123.222.abcdef '), charindex ('. ', reverse ('192. 123.222.abcdef'), 1)-1 ))