---
title: secret function
description: Learn the syntax of the secret function of the SQL language in Databricks.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/secret
---

# `secret` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL preview ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 11.3 LTS and above

Extracts a secret value with the given `scope` and `key` from [Databricks secret service](https://docs.databricks.com/aws/en/security/secrets/index.md).

## Syntax

```
secret ( scope, key )
```

## Arguments

* `scope`: A constant string expression containing the scope of the secret to be extracted. The scope is the namespace in which multiple keys might reside.
* `key`: A constant string expression with the key of the secret to be extracted.

## Returns

A `STRING`.

If the key cannot be retrieved the function raises [INVALID\_SECRET\_LOOKUP](https://docs.databricks.com/aws/en/error-messages/invalid-secret-lookup-error-class.md).
To return `NULL` instead, use the [try\_secret()](https://docs.databricks.com/aws/en/sql/language-manual/functions/try_secret.md) function.

To retrieve a list of all secrets the user is authorized to see use the [list\_secrets](https://docs.databricks.com/aws/en/sql/language-manual/functions/list_secrets.md) function.

> [!NOTE]
>
> Databricks makes a best-effort attempt to redact secrets from raw output. For more information, see [Secret redaction](https://docs.databricks.com/aws/en/security/secrets/workspace-secret-scopes.md#redaction).

## Common error conditions

* [INVALID\_SECRET\_LOOKUP](https://docs.databricks.com/aws/en/error-messages/invalid-secret-lookup-error-class.md)

## Examples

```sql
> SELECT * FROM list_secrets();
  scope         key
  ------------  ---------------
  secrets.r.us  theAnswerToLife

> SELECT secret('secrets.r.us', 'theAnswerToLife');
  fourtyTwo

> SELECT secret('secrets.r.us', 'WhatIsTheAnswerToLife');
  Error: INVALID_SECRET_LOOKUP.SECRET_FUNCTION_LOOKUP_FAILED
```

## Related functions

* [`list_secrets` table function](https://docs.databricks.com/aws/en/sql/language-manual/functions/list_secrets.md)
* [`try_secret` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/try_secret.md)
