Reference link: MySQL's varchar length issue
Today, I made a demo with MySQL and created a table:
--Loan FormCREATE TABLEJK (IDint(5) not NULLAuto_increment,--self-increment IDAmountint not NULL,--Loan PrincipalRemarkvarchar(255),--Notes/Summary PRIMARY KEY(' id '));Insert intoJK (Amount,remark)Values(20000,'Zhang Zhangsan Borrowing');Insert intoJK (Amount,remark)Values(10000,'pay the King small five borrowings');Insert intoJK (Amount,remark)Values(80000,'Yu Yuwen small four borrowings'); Insert intoJK (Amount,remark)Values(20000,'Zhang Zhangsan 12ab borrowing');
Because this table has no person's name the key (temporarily does not consider the name duplicates), wants to remove the bearer name, can only remark the field to do the disassembly.
Of course, the method of dismantling more than one, my train of thought is through length, left, right three functions, the name of the borrower is disassembled.
The specific idea is to remove the " str_l" from the left first without "borrowing", and then remove the word "pay" by the right function on the str_l . Then you get the middle name.
Then the code I wrote was:
--Note: This is the wrong wording!!!SelectJk.id,jk.amount,jk.remark, Left(Jk.remark,length (Jk.remark)-2) as 'left', # Get rid of "borrowing" 2 words Right(Jk.remark,length (Jk.remark)-1) as 'Right', # Remove the word "pay" Right( Left(Jk.remark,length (Jk.remark)-2), Length ( Left(Jk.remark,length (Jk.remark)-2))/3-1 ) asname fromjk
Looks like there is no problem, first take the length, "borrowing" is two words, so minus 2; "Pay" is a word, so minus 1. Rookie like me Ah ~.
And then it turned out to be a whale.
MySQL's varchar type small note