编辑表达式 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
将时间戳 NTZ(不带时区的时间戳)转换为 TZ(带时区的时间戳),并应用定义的会话 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
返回由经度和纬度定义的两点之间的距离(以度表示)
Distance(<经度 A>, <纬度 A>, <经度 B>, <纬度 B>)

数值

数值函数用于将文本转换为数字。

名称
说明
语法
Abs
返回数字的绝对值
Abs(<数字>)
Ceil
返回大于或等于某个数字的最小整数
Ceil(<数字>)
Floor
返回大于或等于某个数字的最大整数
Floor(<数字>)
Greatest
返回两个数字中的较大者
Greatest(<数字 1>, <数字 2>)
Least
返回两个数字中的较小者
Least(<数字 1>, <数字 2>)
Mod
返回 n1 除以 n2 的整数除法的余数
Mod(<数字 1>, <数字 2>)
Percent
返回两个数字的比值,以百分比表示
Percent(<数字 1>, <数字 2>)
Random
返回随机值
Random()
Round
将数字舍入为 n 位小数
Round(<数字>, <小数>)
Sign
返回数字的符号
Sign(<数字>)
ToDouble
将整数转换为浮点
ToDouble(<数字>)
ToInt64
将浮点转换为 64 位整数
ToInt64(<数字>)
ToInteger
将浮点转换为整数
ToInteger(<数字>)
Trunc
将 n1 取整到 n2 位小数
Trunc(<n1>, <n2>)

其他

此表还包含其余一些可用的函数。

名称
说明
语法
AESEncrypt
对参数中提供的字符串进行加密
AESEncrypt(<值>)
Case
如果条件为真,则返回值 1。 如果为假,则返回值 2。
Case(When(<条件>, <值 1>), Else(<值 2>))
ClearBit
删除值中的标志
ClearBit(<标识符>, <标识>)
Coalesce
如果值 1 为 0 或 null,则返回值 2,否则返回值 1
Coalesce(<值 1>, <值 2>)
Decode
如果值 1 = 值 2,则返回值 3。 否则返回值 4。
Decode(<值 1>, <值 2>, <值 3>, <值 4>)
Else
返回值 1(只能用作 case 函数的参数)
Else(<值 1>, <值 2>)
GetEmailDomain
从电子邮件地址提取域名
GetEmailDomain(<值>)
GetMirrorURL
检索镜像页面服务器的 URL
GetMirrorURL(<值>)
Iif
如果表达式为真,则返回值 1。 否则,则返回值 2
Iif(<条件>, <值 1>, <值 2>)
IsBitSet
指示标志是否在值中
IsBitSet(<标识符>, <标识>)
IsEmptyString
如果字符串 1 为空,则返回值 2,否则返回值 3
IsEmptyString(<值 1>, <值 2>, <值 3>)
NewUUID
返回唯一 ID
NewUUID()
NoNull
如果参数为 NULL,则返回空字符串
NoNull(<值>)
RowId
返回行号
RowId
SetBit
强制将标志设在值中
SetBit(<标识符>, <标识>)
ToBoolean
将数字转换为布尔值
ToBoolean(<数字>)
When
如果表达式为真,则返回值 1。 否则,返回值 2(只能用作 case 函数的参数)
When(<条件>, <值 1>)

字符串

字符串函数用于操作一系列字符串。

名称
说明
语法
AllNonNull2
指示所有参数是否为非 null 且不为空
AllNonNull2(<字符串>, <字符串>)
AllNonNull3
指示所有参数是否为非 null 且不为空
AllNonNull3(<字符串>, <字符串>, <字符串>)
Ascii
返回字符串中第一个字符的 ASCII 值。
Ascii(<字符串>)
Char
返回与 ASCII 代码"n"对应的字符
Char(<数字>)
Charindex
返回字符串 1 中字符串 2 的位置。
Charindex(<字符串>, <字符串>)
dataLength
返回字符串的大小(以字节为单位)
dataLength(<字符串>)
GetLine
返回字符串的 n(从 1 到 n)行
GetLine(<字符串>)
IfEquals
如果前两个参数相等,则返回第三个参数。 否则返回最后一个参数
IfEquals(<字符串>, <字符串>, <字符串>, <字符串>)
IsMemoNull
指示作为参数传递的 Memo 是否为 null
IsMemoNull(<备注>)
JuxtWords
将作为参数传递的字符串连接起来。 必要时在字符串之间添加空格。
JuxtWords(<字符串>, <字符串>)
JuxtWords3
将作为参数传递的字符串连接起来。 必要时在字符串之间添加空格
JuxtWords3(<字符串>, <字符串>, <字符串>)
Left
返回字符串的前 n 个字符
Left(<字符串>, <数字>)
Length
返回字符串的长度
Length(<字符串>)
行
从字符串中提取第 n 行
Line(<字符串>, <数字>)
Lower
以小写形式返回字符串
Lower(<字符串>)
LPad
返回左侧的已完成字符串
LPad (<字符串>, <数字>, <字符>)
Ltrim
删除字符串左侧的空格
Ltrim(<字符串>)
Md5Digest
返回字符串以十六进制表示的 MD5 键值
Md5Digest(<字符串>)
MemoContains
指定 Memo 是否包含作为参数传递的字符串
MemoContains(<备注>, <字符串>)
NodeValue
从 XML 字段的 XPath 和字段数据中提取 XML 字段的值
NodeValue (<字符串>, <字符串>)
Replace
将出现的所有指定字符串替换为其他字符串值。
Replace(<字符串>,<字符串>,<字符串>)
Right
返回字符串的最后 n 个字符
Right(<字符串>)
RPad
返回右侧的已完成字符串
RPad(<字符串>, <数字>, <字符>)
Rtrim
删除字符串右侧的空格
Rtrim(<字符串>)
Sha256Digest
以十六进制表示的字符串的 SHA256 键。
Sha256Digest (<字符串>)
Sha512Digest
以十六进制表示的字符串的 SHA512 键。
Sha512Digest (<字符串>)
Smart
以大写方式返回带每个单词的第一个字母的字符串
Smart(<字符串>)
Substring
提取从字符串的字符 n1 开始、长度为 n2 的子字符串
Substring(<字符串>, <偏移>, <长度>)
ToString
将数字转换为字符串
ToString(<数字>, <数字>)
Upper
返回以大写表示的字符串
Upper(<字符串>)
VirtualLink
如果其他两个参数相等,则返回作为参数传递的链接的外键
VirtualLink(<数字>, <数字>, <数字>)
VirtualLinkStr
如果其他两个参数相等,则返回作为参数传递的链接的外键(文本)
VirtualLinkStr(<字符串>, <数字>, <数字>)

窗口

名称
说明
语法
_Over__
相对于作为第二个参数输入的“分区”或“排序依据”字段,优先执行作为第一个参数输入的 SQL 函数调用
_Over_ (<值>, <值>)
Desc
应用降序排序
Desc(<值 1>)
OrderBy
对分区中的结果进行排序
OrderBy(<值 1>)
PartitionBy
对表格上的查询结果进行分区
PartitionBy(<值 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