mysql function insert_MySQL – How INSERT() Function Works for MySQL_MySQL

You know there is an INSERT statement which is used to add data to a table. But did you know that there is an INSERT function which will replace certain characters within a string?

INSERT ( ) function in MySQL is used to insert a substring at the specified position up to the specified number of characters.

Let us consider this example.set @str:='This is nothing';

The variable @str has a string value “This is nothing”. Suppose you want to change “nothing” into “everything” in this string. You can use INSERT ( ) function as shown belowselect INSERT(@str,9,2,'every');

The INSERT ( ) function replaces the characters starting from the position 9 to next 2 characters by “everything”. So in the string part “nothing”, no is replaced by “every” and the full string becomes “This is everything” .

1405K441131250-41A3.jpg

You can also add a string between two strings as shown belowset @str:='This is nothing'; select INSERT(@str,9,0,'not ');

The result is “This is not nothing”. When the third parameter is 0, it will not replace any characters, but append it at the starting position defined in the second parameter

Note: This INSERT ( ) function is functionally equivalent to SQL Server’s STUFF ( ) function. You can refer the usage of STUFF ( ) function in this post .

Reference: Pinal Dave ( http://blog.sqlauthority.com )

相关标签:

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值