What is the undescore "_" in the MYSQL LIKE?

Asked

Viewed 558 times

6

  • Before criticizing me saying that I did not research: I did, and I did not find anything in Portuguese.

  • https://www.google.com/search?client=ubuntu&channel=fs&q=pra+que+serve+o+undescore+no+MSQL&ie=utf-8&oe=utf-8&gfe_rd=cr&ei=J_T6VZOfG8aw8wfRhaL4Dw#safe=active&channel=fs&q=para+que+serve+o+underscore+no+MYSQL

  • 1

    Most search results are in English, not Portuguese. Try searching in English or looking in the manual itself, there responds directly. Sorry I don’t answer, I’m on my cell phone.

  • Now we will have a source in Portuguese then - my question.

  • 1

    hauhau turn down for what!

  • 2

    I had to use Google translator @Danielomine. And he said turn down to what!

  • this phrase is from a song and went viral. search on youtube that you will understand. hehe

Show 2 more comments

2 answers

11


The underscore (_) serves to compare any character only once, while the percentage (%) means any character in any quantity.

(_) is equivalent to meta character (.) of regular expressions and (%) at the (.*)

Mysql - like

  • When you quoted it in the other answer I had not understood. Now I understood.

1

The underscores _ is to find occurrences at certain position of the string.

Let’s assume I’ll want to search every string that starts with my.

LIKE 'my%'

Will return me records as: mySQL, Myan, Mylan and etc.

Let’s start from the example I wanted to research my but from the third position of the string.

LIKE '___my%'

Will return me records as hjjmy, yuimy and on.

There are other pattern matching for the like as for example: \_ and even ESCAPE.

Edit

Also to mark occurrences positions.

As in the example:

SELECT 'David!' LIKE '_____';

Will get output 0 because I searched for strings that contain 5 occurrences, already David! contains 6 occurrences.

If I use:

SELECT 'David!' LIKE '______';

Will get output 1

Already expression:

SELECT 'David32' LIKE '_____\32';

Will confront if _____ 32 equals David32.

That is, 5 occurrences forward plus number 32 exists?

It will return all names containing 7 occurrences and the last two occurrences are: 32

References: http://dev.mysql.com/doc/refman/5.6/en/string-comparison-functions.html#operator_like

https://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.