为了从存储在MySQL表的列中的数据中获取一些起始字符,我们可以使用MySQLLEFT()
函数。它将返回指定为其参数的字符数。我们需要提供该列的名称作为其第一个参数,该列具有要从中获取起始字符的特定记录。为了证明这一点,我们以名为“ examination_btech”的表为例,该表具有以下学生的考试详细信息-
mysql> Select * from examination_btech; +-----------+----------+--------+ | RollNo | Name | Course | +-----------+----------+--------+ | 201712001 | Rahul | B.tech | | 201712002 | Raman | B.tech | | 201712003 | Sahil | B.tech | | 201712004 | Shalini | B.tech | | 201712005 | Pankaj | B.tech | | 201712006 | Mohan | B.tech | | 201712007 | Yash | B.tech | | 201712008 | digvijay | B.tech | | 201712009 | Gurdas | B.tech | | 201712010 | Preeti | B.tech | +-----------+----------+--------+ 10 rows in set (0.00 sec)
现在,如果我们想从滚动系列中获取前六个字符,则可以借助以下LEFT()
方法来完成它-
mysql> Select LEFT(RollNo, 6) FROM examination_btech; +-----------------+ | LEFT(RollNo, 6) | +-----------------+ | 201712 | | 201712 | | 201712 | | 201712 | | 201712 | | 201712 | | 201712 | | 201712 | | 201712 | | 201712 | +-----------------+ 10 rows in set (0.00 sec)