Skip to content

ENDSWITH()

Function Description

Checks whether it ends with the specified suffix. The string returns 1 if ends with the specified suffix, otherwise returns 0. This function is case sensitive.

Function Syntax

> ENDSWITH(str,suffix)

Parameter definition

Parameters Description
str Required parameters. Both CHAR and VARCHAR types are supported.
suffix Required parameters. Both CHAR and VARCHAR types are supported.

Return value

  • 1, if the string ends with the specified suffix.
  • 0, if the string does not end with the specified suffix.

Example

> drop table if exists t1;
> create table t1(a int,b varchar(100),c char(20));
> insert into t1 values
(1,'Ananya Majumdar', 'XI'),
(2,'Anushka Samanta', 'X'),
(3,'Aniket Sharma', 'XI'),
(4,'Anik Das', 'X'),
(5,'Riya Jain', 'IX'),
(6,'Tapan Samanta', 'XI');
> select a,endsWith(b,'a') from t1;
+------------------------------+
| a | endswith(b, a) |
+------------------------------+
| 1 | 0 |
| 2 | 1 |
| 3 | 1 |
| 4 | 0 |
| 5 | 0 |
| 6 | 1 |
+------------------------------+
> select a,b,c from t1 where endswith(b,'a')=1 and endswith(c,'I')=1;
+------------------------+
| a | b | c |
+------------------------+
| 3 | Aniket Sharma | XI |
| 6 | Tapan Samanta | XI |
+------------------------+