So all right, we're writing our text box that people can search for stuff. In fact, we're gonna use another one here in just a second. I wanted to show you how to use a built-in function because those end up being pretty important. We can make this all sorts of weird things. You can just say ILIKE, which is insensitive like, right? And then you get this it works just fine it doesn't matter. But there's actually a lot easier way to do that. So LOWER is a function is gonna take everything in title and make it lowercase, right? Same thing you could do upper and then you just have to make sure that your search string can contain uppercase characters and that would also work as well. This capital is kind of making it mess up because of this, right? It's not matching that P, there's a couple options here of things you can do. Now there's still a problem with this if I do capital P, well like this. And again this won't show up anything because you're not giving it any space. LIKE basically says like this is going to show up somewhere in here and I'll give you some sort of pattern to match. This would also match this, right, because it does actually start with pota, okay? So, if we put it here, that means that pota shows up somewhere in the string, right? And there you go. And then, it would give you anything that ends in pota, obviously that's not anything. Instead of saying equals, you're gonna say LIKE And then you have to say WHERE is it LIKE, right? So if you wanna search for everything where it's just like it ends in pota you would do this. We need something that's a little bit more fuzzy, right? So the way that we can do that is with something called LIKE. As you might guess, that doesn't work, right, why? Well, nothing equals potatoes, right? It's actually doing like a full equality check. If someone says search for pota, you would expect that to show up potatoes, right, I think that's pretty reasonable. So imagine you're writing something where people can like search for stuff, right? Imagine someone can type a little text string and then it's gonna go search your database to find things like that. So the section we're on here is like and functions under the data section. > We are gonna talk about functions and we're gonna look at some text search. Transcript from the "Using LIKE, ILIKE, & SQL Functions" Lesson
0 Comments
Leave a Reply. |