編輯運算式 edit-expressions

在此頁面上:​瞭解如何使用運算式編輯器以手動方式建立規則,包含資料庫欄位、變數和協助程式函式,以操控協調行銷活動中的日期、字串和數值。

NOTE
下節提供如何使用運算式編輯器建立規則的資訊。 請記住,用來建立規則的語法與用來新增個人化的語法不同。

使用運算式編輯器 edit

編輯運算式需要手動輸入條件以形成規則。 此模式可讓您使用進階函式,這些函式可讓您操作用於執行特定查詢的值,例如操作日期、字串、數值欄位和排序。

設定自訂條件時,可按下規則產生器的「編輯運算式」按鈕打開運算式編輯器,適用於「屬性」和「值」欄位。

從「屬性」欄位存取
從「值」欄位存取
「屬性」欄位的運算式編輯器 {align="center" width="200" modal="regular"}
「值」欄位的運算式編輯器 {align="center" width="200" modal="regular"}

運算式編輯器提供:

  • 定義運算式的​輸入欄位 (1)。

  • 可用​欄位 (2) 清單,可用於運算式中,並對應至查詢的目標維度。

  • 可用於運算式中的可用​ 變數(3) ​清單。 此功能表適用於​ 值 ​欄位。 瞭解如何在協調的行銷活動中使用變數

  • 協助程式函式(4),依類別排序。

直接在輸入欄位中輸入運算式以編輯運算式。 若要新增欄位、變數或協助程式函式,請將游標置於要新增的運算式中,然後按一下+按鈕。

運算式編輯器介面 {modal="regular"}

協助程式功能

查詢編輯工具可讓您使用進階功能,根據所需結果和操作資料的類型執行複雜的篩選。 可使用下列函式:

彙總

彙總函式會針對一組值執行計算。

名稱
說明
語法
Avg
傳回數值類型欄的平均值
Avg(<值>)
Count
計算欄的非空值數量。
Count(<值>)
CountAll
計算傳回的值 (所有欄位)
CountAll()
Countdistinct
計算欄中不同的非空值數量
Countdistinct(<值>)
Max
傳回數值、字串或日期類型欄位中的最大值
Max(<值>)
Min
傳回數值、字串或日期類型欄中的最小值
Min(<值>)
StdDev
傳回數值、字串或日期欄位中的標準差
StdDev(<值>)
StringAgg
傳回字串類型欄位值的串連,並以第二個引數中的字元分隔
StringAgg(<值>, <字串>)
Sum
傳回數字、字串或日期類型欄位值的總和
Sum(<值>)

日期

日期函數可操控日期或時間值。

名稱
說明
語法
AddDays
將天數新增至日期
AddDays(<日期>, <數字>)
AddHours
將時數新增至日期
AddHours(<日期>, <數字>)
AddMinutes
將分鐘數新增至日期
AddMinutes(<日期>, <數字>)
AddMonths
將月份新增至日期
AddMonths(<日期>, <數字>)
AddSeconds
將秒數新增至日期
AddSeconds(<日期>, <數字>)
AddYears
將年數新增至日期
AddYears(<日期>, <數字>)
ConvertNTZ
套用定義的工作階段 TZ,就能將時間戳記 NTZ (沒有時區的時間戳記) 轉換成 TZ (有時區的時間戳記)
ConvertNTZ(<日期+時間>)
DateCmp
比較兩個日期
DateCmp(<日期>, <日期>)
DateOnly
只會傳回日期 (時間設在 00:00)
DateOnly(<日期>)
Day
傳回日期中代表日的數字
Day(<日期>)
DayOfYear
傳回日期在一年中的第幾天
DayOfYear(<日期>)
DaysAgo
傳回與目前日期減去 n 天相對應的日期
DaysAgo(<數字>)
DaysAgoInt
傳回與目前日期減去 n 天相對應的日期(整數 yyyymmdd)
DaysAgoInt(<數字>)
DaysDiff
傳回兩個日期之間的天數
DaysDiff(<結束日期>, <開始日期>)
DaysOld
傳回日期的年齡 (以天為單位)
DaysOld(<日期>)
GetDate
返回伺服器的目前系統日期
GetDate()
Hour
傳回日期的小時數
Hour(<日期>)
HoursDiff
傳回兩個日期之間的小時數
HoursDiff(<結束日期>, <開始日期>)
Minute
傳回日期的分鐘數
Minute(<日期>)
MinutesDiff
傳回兩個日期之間的分鐘數
MinutesDiff(<結束日期>, <開始日期>)
Month
傳回代表日期月份的數字
Month(<日期>)
MonthsAgo
傳回與目前日期減去 n 個月相對應的日期
MonthsAgo(<數字>)
MonthsDiff
傳回兩個日期之間的月數
MonthsDiff(<結束日期>, <開始日期>)
MonthsOld
傳回日期的年齡 (以月為單位)
MonthsOld(<日期>)
Oldest
傳回範圍中最早的日期
Oldest(<日期, 日期>)
Second
傳回日期的秒數
Second(<日期>)
SecondsDiff
傳回兩個日期之間的秒數
SecondsDiff(<結束日期>, <開始日期>)
SubDays
從日期減去天數
SubDays(<日期>, <數字>)
SubHours
從日期減去小時數
SubHours(<日期>, <數字>)
SubMinutes
從日期減去分鐘數
SubMinutes(<日期>, <數字>)
SubMonths
從日期減去月數
SubMonths(<日期>, <數字>)
SubSeconds
從日期減去秒數
SubSeconds(<日期>, <數字>)
SubYears
從日期減去年數
SubYears(<日期>, <數字>)
ToDate
將日期 + 時間轉換為日期
ToDate(<日期 + 時間>)
ToDateTime
將字串轉換為日期 + 時間
ToDateTime(<字串>)
ToTimestamp
將字串轉換為時間戳記
ToTimestamp(<字串>)
ToTimeZone
將日期 + 時間轉換為時區
ToTimeZone(<日期>, <時區>)
TruncDate
將日期 + 時間四捨五入至最接近的秒數
TruncDate(@lastModified, <秒數>)
TruncDateTZ
將日期 + 時間四捨五入為以秒為單位的指定精確度
TruncDateTZ(<日期>, <秒數>, <時區>)
TruncQuarter
將日期捨入為季度
TruncQuarter(<日期>)
TruncTime
將時間部分捨入到最接近的秒數
TruncTime(<日期>, <秒數>)
TruncWeek
將日期捨入為一週
TruncWeek(<日期>)
TruncYear
將日期 + 時間捨入至年度的 1 月 1 日
TruncYear(<日期>)
WeekDay
傳回代表日期是星期幾的數字 (0=星期一,6=星期日)
WeekDay(<日期>)
Year
傳回代表日期年份的數字
Year(<日期>)
YearAndMonth
傳回代表日期的年月份數字
YearAndMonth(<日期>)
YearsAgo
傳回指定日期與目前日期之間的年數
YearsAgo(<日期>)
YearsDiff
傳回兩個日期之間的年數
YearsDiff(<結束日期>, <開始日期>)
YearsOld
傳回日期的年齡
YearsOld(<日期>)
NOTE
請注意,DateOnly​函式會考量伺服器的時區,部會只計算運算子所在時區。

地理行銷

地理行銷函式用於處理地理值。

名稱
說明
語法
距離
傳回由經度和緯度,通常會以度來表示,定義兩點之間的距離
Distance(<經度 A>, <緯度 A>, <經度 B>, <緯度 B>)

數值

數值函數可用來將文轉換為數字。

名稱
說明
語法
Abs
返回數字的絕對值
Abs(<number>)
Ceil
傳回大於或等於數字的最小整數
Ceil(<number>)
Floor
傳回大於或等於數字的最小整數
Floor(<number>)
Greatest
傳回兩個數字中的較大值
Greatest(<number 1>, <number 2>)
Least
傳回兩個數字中的較小者
Least(<number 1>, <number 2>)
Mod
傳回 n1 除以 n2 的整數餘數
Mod(<number 1>, <number 2>)
Percent
傳回兩個數字的比率,以百分比表示
Percent(<number 1>, <number 2>)
Random
傳回隨機值
Random()
Round
將數字四捨五入為n個小數
Round(<number>, <number of decimals>)
Sign
傳回數字元號
Sign(<number>)
ToDouble
將整數轉換為浮點數
ToDouble(<number>)
ToInt64
將浮點數轉換為 64 位整數
ToInt64(<number>)
ToInteger
將浮點數轉換為整數
ToInteger(<number>)
Trunc
截斷 n1 到 n2 小數
Trunc(<n1>, <n2>)

其他

此表包含剩餘的可用函式。

名稱
說明
語法
AESEncrypt
加密引數中提供的字串
AESEncrypt(<值>)
案例
如果條件為真,則傳回值 1。 如果為假,則傳回值 2。
Case(When(<condition>, <value 1>), Else(<value 2>))
ClearBit
刪除值中的旗標
ClearBit(<identifier>, <flag>)
合併
如果值 1 為 零或 null,則傳回值 2,否則傳回值 1
Coalesce(<value 1>, <value 2>)
Decode
如果值 1 = 值 2,則傳回值 3。 如果不等,則傳回值 4。
Decode(<value 1>, <value 2>, <value 3>, <value 4>)
Else
傳回值 1(只能用作 case 函式的參數)
Else(<值 1>, <值 2>)
GetEmailDomain
從電子郵件地址中擷取網域
GetEmailDomain(<value>)
GetMirrorURL
檢索鏡像頁面伺服器的URL
GetMirrorURL(<value>)
Iif
如果運算式為真,則傳回值 1。 如果為假,則傳回值 2
Iif(<condition>, <value 1>, <value 2>)
IsBitSet
指出旗標是否在值中
IsBitSet(<identifier>, <flag>)
IsEmptyString
如果字串 1 為空,則傳回值 2,否則傳回值 3
IsEmptyString(<值 1>, <值 2>, <值 3>)
NewUUID
傳回唯一識別碼
NewUUID()
NoNull
如果引數為 NULL,則返回空字串
NoNull(<value>)
RowId
返回行號
RowId
SetBit
強制值中的旗標
SetBit(<identifier>, <flag>)
ToBoolean
將數字轉換為布林值
ToBoolean(<number>)
When
如果運算式為真,則傳回值 1。 否則,傳回值 2 (只能用作 case 函式的參數)
When(<條件>, <值 1>)

字串

字串函式可用來處理字串集合。

名稱
說明
語法
AllNonNull2
指示所有參數是否為非空值且非空白
AllNonNull2(<字串>, <字串>)
AllNonNull3
指示所有參數是否為非空值且非空白
AllNonNull3(<字串>, <字串>, <字串>)
Ascii
傳回字串中第一個字元的 ASCII 值
Ascii(<字串>)
Char
傳回與 'n' ASCII 代碼對應的字元
Char(<數字>)
Charindex
傳回字串 2 在字串 1 中的位置。
Charindex(<字串>, <字串>)
DataLength
傳回字串的位元組大小
dataLength(<字串>)
GetLine
傳回字串的第 n 行 (從 1 到 n)
GetLine(<字串>)
IfEquals
如果前兩個參數相等,就會傳回第三個參數。 如果不是,就會傳回最後一個參數
IfEquals(<字串>, <字串>, <字串>, <字串>)
IsMemoNull
指示作為參數傳遞的備忘錄是否為空
IsMemoNull(<備忘錄>)
JuxtWords
將作為參數傳遞的字串串連起來。 如有必要,請在字串之間新增空格。
JuxtWords(<字串>, <字串>)
JuxtWords3
將作為參數傳遞的字串串連起來。 如有必要,請在字串之間新增空格
JuxtWords3(<字串>, <字串>, <字串>)
Left
傳回字串的前 n 個字元
Left(<字串>, <數字>)
Length
傳回字串的長度
Length(<字串>)
Line
從字串中擷取第 n 行
Line(<字串>,<數字>)
Lower
傳回小寫字串
Lower(<字串>)
LPad
傳回左側的已完成字串
LPad (<字串>, <數字>, <字元>)
Ltrim
移除字串左側的空格
Ltrim(<字串>)
Md5Digest
返回字串 MD5 鍵的十六進位表示
Md5Digest(<字串>)
MemoContains
指定備忘錄是否包含作為參數傳遞的字串
MemoContains(<備忘錄>, <字串>)
NodeValue
從 XPath 和欄位資料中擷取到 XML 欄位的數值
NodeValue (<字串>, <字串>)
Replace
將出現的所有指定字串值,換成其他字串值。
Replace(<字串>,<字串>,<字串>)
Right
傳回字串的最後 n 個字元
Right(<string>)
RPad
傳回右側的已完成字串
RPad(<字串>, <數字>, <字元>)
Rtrim
移除字串右側的空格
Rtrim(<string>)
Sha256Digest
字串 SHA256 鍵的十六進位表示。
Sha256Digest (<字串>)
Sha512Digest
字串 SHA512 鍵的十六進位表示。
Sha512Digest (<字串>)
Smart
傳回字串,每個字詞的首字母以大寫表示
Smart(<string>)
Substring
從字串的字元 n1 開始提取長度為 n2 的子字串
Substring(<string>, <offset>, <length>)
ToString
將數字轉換為字串
ToString(<數字>, <數字>)
Upper
以大寫傳回字串
Upper(<string>)
VirtualLink
傳回連結的外鍵,如果其他兩個參數相等,則傳遞為參數
VirtualLink(<number>、<number>、<number>)
VirtualLinkStr
傳回連結的外鍵(文字)索引鍵,如果其他兩個參數相等,則傳回該連結的外鍵 (text)
VirtualLinkStr(<字串>, <數字>, <數字>)

視窗

名稱
說明
語法
_Over__
執行以第 1 個參數輸入的 SQL 函式呼叫,取代以第 2 個參數輸入的「分割」或「排序」欄位
_Over_ (<值>, <值>)
Desc
套用遞減排序
Desc(<value 1>)
OrderBy
對分區內的結果進行排序
OrderBy(<value 1>)
PartitionBy
對表上的查詢結果進行分區
PartitionBy(<value 1>)
RowNum
根據表格分割和排序序列產生行號。
RowNum(PartitionBy(<值 1>), OrderBy(<值 1>))
AI Knowledge Reference

This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.

For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.

  • TL;DR: This page explains how to use the expression editor to manually build rule conditions with fields, variables, and helper functions for manipulating dates, strings, numbers, and other values in Orchestrated campaigns.

Intents:

  • Open the expression editor from the Attribute or Value field when configuring a custom condition in the rule builder.
  • Enter an expression directly in the input field, or insert a field, variable, or helper function using the + button.
  • Use helper functions (Aggregate, Date, Geomarketing, Numeric, Others, String, Window) to manipulate dates, strings, numeric values, and sorting.
  • Insert variables into an expression from the Value field.

Glossary:

  • Expression editor: a mode accessed from the rule builder Edit expression button that lets you manually enter conditions to form a rule, using advanced functions (product-specific)
  • Helper functions: functions sorted by category (Aggregate, Date, Geomarketing, Numeric, Others, String, Window) available in the expression editor to manipulate values (product-specific)
  • Fields: items available in the expression editor that correspond to the targeting dimension of the query (product-specific)
  • Variables: items available in the expression editor, from the Value field menu, that can be used in an expression (product-specific)

Guardrails:

  • The expression editor is available from the rule builder Edit expression button, for the Attribute and Value fields, when configuring a custom condition.
  • The variables menu in the expression editor is available only for the Value field, not for the Attribute field.
  • The DateOnly function takes into account the server’s timezone, not the operator’s.

Terminology:

  • Canonical name: expression editor — variants: Edit expression
  • Do not confuse: “fields” (correspond to the targeting dimension of the query) ≠ “variables” (listed in a separate menu, available from the Value field)

FAQ:

  • Q: Where is the expression editor available from? — The rule builder Edit expression button, for the Attribute and Value fields, when configuring a custom condition.
  • Q: How do I add a field, variable, or helper function to an expression? — Place your cursor in the expression where you want to add it and click the + button.
  • Q: What categories of helper functions are available? — Aggregate, Date, Geomarketing, Numeric, Others, String, and Window.
  • Q: Does the DateOnly function use my local timezone? — No, it takes into account the server’s timezone, not the operator’s.
  • Q: Can I use variables from the Attribute field? — No, the variables menu is available only for the Value field.

Related pages:

  • For using variables in an expression from the Value field: Learn how to use variables in Orchestrated campaigns (orchestrated/variables-orchestrated-campaigns.md)

Personas:

  • marketer: Can open the expression editor from the Attribute or Value field when configuring a custom condition, and enter an expression directly in the input field. Can place the cursor and select the + button to add a field, variable, or helper function. Can use helper functions sorted by category, such as Aggregate, Date, Geomarketing, Numeric, Others, String, and Window, to manipulate dates, strings, numeric values, and sorting. The page states that the variables menu is available only for the Value field. Where: “Work with the expression editor”.

Onboarding:

  • Level: Experienced
  • First minimal step: Select the Edit expression button for the Attribute or Value field when configuring a custom condition.
  • Next: Learn how to use variables in the expression editor: Use variables in Orchestrated campaigns (orchestrated/variables-orchestrated-campaigns.md)
recommendation-more-help
journey-optimizer-help