STARTSWITH()

Description

Returns 1 whether string starts with the specified prefix, otherwise it returns 0.This function is case sensitive.

Syntax

  1. > STARTSWITH(str,prefix)

Arguments

ArgumentsDescription
strRequired. CHAR and VARCHAR both are supported.
prefixRequired. CHAR and VARCHAR both are supported.

Returned Values

  • 1, if the string starts with the specified prefix.
  • 0, if the string does not start with the specified prefix.

Examples

  1. > drop table if exists t1;
  2. > create table t1(a int,b varchar(100),c char(20));
  3. > insert into t1 values
  4. (1,'Ananya Majumdar', 'IX'),
  5. (2,'Anushka Samanta', 'X'),
  6. (3,'Aniket Sharma', 'XI'),
  7. (4,'Anik Das', 'X'),
  8. (5,'Riya Jain', 'IX'),
  9. (6,'Tapan Samanta', 'X');
  10. > select a,startswith(b,'An') from t1;
  11. +------+-------------------+
  12. | a | startswith(b, An) |
  13. +------+-------------------+
  14. | 1 | 1 |
  15. | 2 | 1 |
  16. | 3 | 1 |
  17. | 4 | 1 |
  18. | 5 | 0 |
  19. | 6 | 0 |
  20. +------+-------------------+
  21. > select a,b,c from t1 where startswith(b,'An')=1 and startswith(c,'I')=1;
  22. +------+-----------------+------+
  23. | a | b | c |
  24. +------+-----------------+------+
  25. | 1 | Ananya Majumdar | IX |
  26. +------+-----------------+------+