try_to_time 函數

適用於:已勾選為 Databricks SQL 勾選為 是 Databricks 執行時 18.3 及以上版本

若投法失敗,則會將 expr 投射回到可選格式 NULL 的某個時間點。

Syntax

try_to_time(expr [, fmt] )

論點

  • expr:一個代表時間的字串表達式。
  • fmt:選擇性格式 STRING 表達式。

Returns

一個 時間

如果 fmt 提供,它必須符合 Datetime 模式

fmt 不提供,則該函數等價於 cast(expr AS TIME)

如果fmt畸形,Azure Databricks會升高INVALID_DATETIME_PATTERN

expr 無法用 fmt轉換為時間,則函數返回 NULL

常見錯誤條件

Examples

> SELECT try_to_time('10:30:00');
  10:30:00

> SELECT try_to_time('10:30:00', 'HH:mm:ss');
  10:30:00

> SELECT try_to_time('not-a-time');
  NULL

> SELECT try_to_time('10:30:00', 'HH:mm:ss') IS NOT NULL;
  true