> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 用于处理 ULID 的函数文档

# 用于处理 ULID 的函数

<Note>
  以下文档根据 `system.functions` 系统表生成。
</Note>

{/*AUTOGENERATED_START*/}

<div id="ULIDStringToDateTime">
  ## ULIDStringToDateTime
</div>

引入版本：v23.3.0

此函数用于从 [ULID](https://github.com/ulid/spec) 中提取时间戳。

**语法**

```sql theme={null}
ULIDStringToDateTime(ulid[, timezone])
```

**参数**

* `ulid` — 输入的 ULID。[`String`](/zh/reference/data-types/string) 或 [`FixedString(26)`](/zh/reference/data-types/fixedstring)
* `timezone` — 可选。返回值所用的时区名称。[`String`](/zh/reference/data-types/string)

**返回值**

带毫秒精度的时间戳。[`DateTime64(3)`](/zh/reference/data-types/datetime64)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT ULIDStringToDateTime('01GNB2S2FGN2P93QPXDNB4EN2R')
```

```response title=Response theme={null}
┌─ULIDStringToDateTime('01GNB2S2FGN2P93QPXDNB4EN2R')─┐
│                            2022-12-28 00:40:37.616 │
└────────────────────────────────────────────────────┘
```

<div id="generateULID">
  ## generateULID
</div>

引入版本：v23.2.0

生成一个 [Universally Unique Lexicographically Sortable Identifier (ULID)](https://github.com/ulid/spec)。

**语法**

```sql theme={null}
generateULID([x])
```

**参数**

* `x` — 可选。一个结果为任意受支持数据类型的表达式。其结果值会被丢弃，但如果在一次查询中多次调用该函数，该表达式本身可用于绕过[公共子表达式消除](/zh/reference/functions/regular-functions/overview#common-subexpression-elimination)。[`Any`](/zh/reference/data-types)

**返回值**

返回一个 ULID。[`FixedString(26)`](/zh/reference/data-types/fixedstring)

**示例**

**用法示例**

```sql title=Query theme={null}
SELECT generateULID()
```

```response title=Response theme={null}
┌─generateULID()─────────────┐
│ 01GNB2S2FGN2P93QPXDNB4EN2R │
└────────────────────────────┘
```

**如需在一行中生成多个值的用法示例**

```sql title=Query theme={null}
SELECT generateULID(1), generateULID(2)
```

```response title=Response theme={null}
┌─generateULID(1)────────────┬─generateULID(2)────────────┐
│ 01GNB2SGG4RHKVNT9ZGA4FFMNP │ 01GNB2SGG4V0HMQVH4VBVPSSRB │
└────────────────────────────┴────────────────────────────┘
```

<div id="see-also">
  ## 另请参见
</div>

* [UUID](/zh/reference/functions/regular-functions/uuid-functions)
