Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL LIKE wildcard space character

Tags:

sql

mysql

let's say I have a string in which the words are separated by 1 or more spaces and I want to use that string in and SQL LIKE condition. How do I make my SQL and tell it to match 1 or more blank space character in my string? Is there an SQL wildcard that I can use to do that?

Let me know

like image 444
user765368 Avatar asked Mar 30 '12 15:03

user765368


People also ask

What is the wild card character in the SQL LIKE statement?

SQL Wildcards A wildcard character is used to substitute one or more characters in a string. Wildcard characters are used with the LIKE operator. The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

How do you indicate a space in SQL?

The SPACE() function returns a string of the specified number of space characters.

Is * a wildcard in SQL?

To broaden the selections of a structured query language (SQL-SELECT) statement, two wildcard characters, the percent sign (%) and the underscore (_), can be used. The percent sign is analogous to the asterisk (*) wildcard character used with MS-DOS.

How do you check if a string contains a space in SQL?

SELECT * FROM MYTABLE WHERE INSTR(ColumnName,' ') > 0; Essentially in this query it finds the character position containing first space from the column values and when it finds the first space in it the index value should be greater than 1 and it should display all the records based on that.


2 Answers

If you're just looking to get anything with atleast one blank / whitespace then you can do something like the following WHERE myField LIKE '% %'

like image 141
markblandford Avatar answered Oct 16 '22 07:10

markblandford


If your dialect allows it, use SIMILAR TO, which allows for more flexible matching, including the normal regular expression quantifiers '?', '*' and '+', with grouping indicated by '()'

where entry SIMILAR TO 'hello +there'

will match 'hello there' with any number of spaces between the two words.

I guess in MySQL this is

where entry RLIKE 'hello +there'
like image 6
Jay Avatar answered Oct 16 '22 08:10

Jay