The STARTS_WITH() function determines whether the first argument starts with a specified string in the second argument or not.
- first_argument: the specified argument, which will be the search reference. It can be a string or a column name.
- second_argument: the specified argument, which will have the search keywords.
The input type will be STRING, and the return type is BOOL, shown as true or false.
- It will return NULL for the NULL record.
- It will return true (including the NULL record) if the second_argument is not specified.
Let’s say we have a table with the title petsData, as shown below.
The above query will show the following table:
From the table above, we want to retrieve the values of petname column that start with “J” by using the following query:
It will return true to the pet with a pet starting with the letter J. Otherwise, false.
Here we have the petsData table with a NULL value in the breed column.
For example, we run the STARTS_WITH function but with no specified second_argument:
We will have the following result where the STARTS_WITH will return true to all records (even the null one):