MySQL's varchar type small note

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.