首页 文章资讯内容详情

MySQL查询从具有值EMP1,EMP2,EMP3等的列中删除字符串

2026-06-05 1 花语

要从值EMO1,EMP2等中删除字符串,您需要将RIGHT()与LENGTH()一起使用。让我们首先创建一个表-

create table DemoTable1540 -> ( -> EmployeeCode varchar(20) -> );

使用插入命令在表中插入一些记录-

insert into DemoTable1540 values(EMP9); insert into DemoTable1540 values(EMP4); insert into DemoTable1540 values(EMP8); insert into DemoTable1540 values(EMP6);

使用select语句显示表中的所有记录-

select * from DemoTable1540;

这将产生以下输出-

+--------------+ | EmployeeCode | +--------------+ | EMP9 | | EMP4 | | EMP8 | | EMP6 | +--------------+ 4 rows in set (0.00 sec)

这是从列值中删除字符串的查询-

select right(EmployeeCode,length(EmployeeCode)-3) as onlyDigit from DemoTable1540;

这将产生以下输出-

+-----------+ | onlyDigit | +-----------+ | 9 | | 4 | | 8 | | 6 | +-----------+ 4 rows in set (0.00 sec)