在逻辑表达式中,可将一个文本表达式与另一个字符串(称为 like 条件)进行比较,比较方式是从左至右比较逐个字符。此功能的用法类似于 SQL 查询中的 SQL 关键字 like 的用法。
下面是一个示例:
// variable myVar01 is the string expression // whose contents will be compared to a like criterion myVar01 = "abcdef"; // the next logical expression evaluates to "true" if (myVar01 like "a_c%") ; end
like 条件可以是类型为 CHAR 或 MBCHAR 的文字或项;或者类型为 UNICODE 的项。like 条件可包括下列任何字符:
转义字符之前通常有百分比符号(%)、下划线(_)或另一反斜杠。
将反斜杠用作转义字符(这是缺省行为)时,因为 EGL 使用同一转义字符以允许在任何文本表达式中包括引号,从而会产生问题。在 like 条件的上下文中,必须指定两个反斜杠,原因是运行时可用的文本就是缺少初始斜杠的文本。
建议尽量避免发生此问题。 通过使用稍后示例中所示的转义子句将另一字符指定为转义字符。但是,不能使用双引号(")作为转义字符。
likeCriterion 中的另一字符是要与字符串表达式中的单个字符进行比较的文字。
// variable myVar01 is the string expression // whose contents will be compared to a like criterion myVar01 = "ab%def"; // the next logical expression evaluates to "true" if (myVar01 like "ab\\%def") ; end // the next logical expression evaluates to "true" if (myVar01 like "ab+%def" escape "+") ; end