我们如何使用INSERT()函数将新字符串插入MySQL表的列的值中?
为此,我们需要使用列名作为函数的第一个参数,即在原始字符串的位置INSERT()
。以下示例将展示它-
示例
假设我们要在'Student'表的'year_of_admission'列中添加'/Old',那么我们需要编写以下查询-
mysql> Select INSERT(year_of_admission,5,0,'/Old')As 'Old Admissions' From Student; +-----------------+ | Old Admissions | +-----------------+ | 2001/Old | | 2010/Old | | 2009/Old | | 2017/Old | | 2000/Old | +-----------------+ 5 rows in set (0.00 sec)
我们还可以在上面的查询中如下应用WHERE子句-
mysql> Select INSERT(year_of_admission,5,0,'/Old')As 'Old Admissions' From Student WHERE year_of_admission < '2017'; +----------------+ | Old Admissions | +----------------+ | 2001/Old | | 2010/Old | | 2009/Old | | 2000/Old | +----------------+ 4 rows in set (0.00 sec)