- Categories:
String & binary functions (AI Functions)
AI_ REDACT¶
检测非结构化文本数据中的个人身份信息 (PII) 并对其进行脱敏处理。
语法
使用 AI_REDACT 检测 PII 并对其进行脱敏处理:
实参
必填:
input一个包含可能含有个人身份信息 (PII) 的文本数据的 VARCHAR 值。
可选:
categoriesAn ARRAY of string values that specify the types of PII to be redacted. If not specified, all supported PII categories are redacted. See Detected PII categories for a list of supported categories.
传递不受支持的类别会导致错误。
return_error_detailsBOOLEAN 标志,指示在发生错误时是否返回错误详细信息。当设置为 TRUE 时,该函数返回一个 OBJECT,其中包含值和错误消息,二者之一为 NULL,具体取决于函数是成功还是失败。
要求将会话参数 AI_SQL_ERROR_HANDLING_USE_FAIL_ON_ERROR 设置为 FALSE。
mode用于指定操作模式的 VARCHAR 值。可接受的值:
redact(default): Replaces detected PII with category placeholders, such as [NAME] and [ADDRESS].detect: Returns an OBJECT that contains aspansarray that identifies the location and category of each detected PII instance without redacting the text.
Note
The mode argument is case insensitive.
返回
The return value of AI_REDACT depends on the mode argument.
脱敏模式(默认)
Returns a VARCHAR that contains the input text with PII replaced by category placeholders, such as [NAME] where the input
text was “John Smith”.
检测模式
Returns an OBJECT that contains a spans array. Each element in the array is an OBJECT with the following fields:
category: A VARCHAR value that identifies the PII category (for example,NAMEorADDRESS).start: A NUMBER value that identifies the start index of the PII in the input text.end: A NUMBER value that identifies the end index of the PII in the input text.text: A VARCHAR value that contains the matched PII text.
错误行为
默认情况下,如果 AI_REDACT 无法处理输入,函数将返回错误。如果查询处理多行,则整个查询将失败。
When AI_SQL_ERROR_HANDLING_USE_FAIL_ON_ERROR is set to FALSE, the return value on error depends on the return_error_details
argument. The following table shows the return value based on the return_error_details argument:
return_error_details返回值 描述 FALSE Not passed NULL TRUE OBJECT with valueanderrorfieldsvalue: A VARCHAR value that contains the redacted text, or NULL if an error occurred.error: A VARCHAR value that contains the error message if an error occurred, or NULL if the function succeeded.
For more information about handling errors, see Handle row-level errors in multi-row queries.
使用说明
- For categories of PII that AI_REDACT can redact, see Detected PII categories.
- For limitations in the current version of AI_REDACT, see Limitations.
示例
See Redaction examples.