contains function

Returns true if expr contains subExpr.

Since: Databricks Runtime 10.3

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.

Since: Databricks Runtime 10.5

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