About the field "contains" and "contains in" strings in SQL

Source: Internet
Author: User


1, query the table in a field value "contains" a string of all records of the method

If there is a Name field in the table, the query name contains all the records for "Zhang San", so you can write sql:

STIRNG strsql= "select * from table name WHERE name like '%" + "Zhang San" + "% '";

2. A method for querying all records of a field value "contained in" a string

If the Name field in the query table contains all the records of the string "Three is a good student", you can write sql:

String strsql= "select * from table name WHERE INSTR (' Zhang Three is a good student ', name) >0";

Can be queried, the Name field value in the record includes: Zhang, three, is, a, good, learning, health, Zhang San 、...... And so on all records.

Note: In the SQL string above, change the full-width symbol to a half-width symbol.

About the field "contains" and "contains in" strings in SQL

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.