共用方式為


assert_true 函式

適用於:check marked yes Databricks SQL check marked yes Databricks Runtime

如果 expr 不是 true,則傳回錯誤。

語法

assert_true(condition [, message])

引數

  • conditionBOOLEAN:表達式。
  • message:具有訊息的選擇性 STRING 表達式。 預設值為 '<condition>' is not true!

傳回

如果未傳回任何錯誤,則為不具類型的 NULL

適用於:check marked yes Databricks SQL check marked yes Databricks Runtime 14.2 和更新版本

傳回的錯誤類別是 USER_RAISED_EXCEPTION ,且 SQLSTATEP0001

如需處理錯誤條件的詳細資訊,請參閱 處理錯誤狀況

範例

> SELECT assert_true(0 < 1);
 NULL

> SELECT assert_true(0 > 1);
 [USER_RAISED_EXCEPTION] '0 > 1' is not true! SQLSTATE: P0001

> SELECT assert_true(1 = 2, 'One is not two!');
 [USER_RAISED_EXCEPTION] One is not two! SQLSTATE: P0001