The SqlServer STUFF function corresponds to the INSERT function of mysql

SqlServer STUFF function:

STUFF(<character_expression>,<开始>,<长度>,<character_expression>)

The <character_expression> parameter is the given string data, which can be a constant, variable or column of character or binary data.

The <start> parameter is an integer value that specifies the position to start deleting and inserting. It can be of type BIGINT. If the <start> or <length> parameter is a negative number, a NULL string is returned. If the <start> parameter is longer than the first <character_expression>, a NULL string is returned.

The <length> parameter can be of type BIGINT, which is an integer that specifies the number of characters to be deleted. If <length> is longer than the first <character_expression>, the deletion occurs to the last character in the last <character_expression>

 

DECLARE @Time VARCHAR(10) 

SET @Time = ‘1030’ 

SELECT STUFF(@Time, 3, 0, ‘:’) AS [HH:MM] 

Output: 10:30 

The string we give is @Time, which is 1030. We start from the third position and delete the length as 0. At this time, we insert a colon before 3, and the result is 10:30 as shown in the figure above.

 

DECLARE @CreditCardNumber VARCHAR(20) 

SET @CreditCardNumber = ‘370200199408103544’

SELECT STUFF(@CreditCardNumber, LEN(@CreditCardNumber) -3, 4, 

‘XXXX’) AS [Output] 

Output: 37020019940810XXXX 

As above, we pass the ID card through STUFF and replace the last four digits with XXXX. The above is the most basic usage of STUFF
 


mysql INSERT函数:

mysql> SELECT INSERT('abcdef', 2, 3, 'ijklmn');

+----------------------------------+

INSERT('abcdef', 2, 3, 'ijklmn') |

+----------------------------------+

| aijklmnef                        |

+----------------------------------+

Guess you like

Origin blog.csdn.net/u013282737/article/details/88945439