contains function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 10.4 LTS and above

Returns true if expr contains subExpr.

Syntax

contains(expr, subExpr)

Arguments

  • expr: A STRING or BINARY within which to search.
  • subExpr: The STRING or BINARY to search for.

Returns

A BOOLEAN. If expr or subExpr are NULL, the result is NULL. If subExpr is the empty string or empty binary the result is true.

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 11.3 LTS and above

The function operates in BINARY mode if both arguments are BINARY.

Examples

> SELECT contains(NULL, 'Spark');
  NULL

> SELECT contains('SparkSQL', NULL);
  NULL

> SELECT contains('SparkSQL', 'Spark');
  true

> SELECT contains('SparkSQL', 'ark');
  true

> SELECT contains('SparkSQL', 'SQL');
  true

> SELECT contains('SparkSQL', 'Spork');
  false

> SELECT contains('SparkSQL', '');
  true

> SELECT contains(x'120033', x'00');
  true