可以在字符类型的变量中使用函数 max() 吗?

It's possible to use the function max() in a variable with character type?

我需要获取数据库中字符记录的最大数量。

是的,此列定义为字符但包含一系列数字,我们无法在数据库中将此记录的类型更改为数字。

所以,我尝试通过这种方式获取该字符的最大数量:

&embacod = str(max(EmbaCod.ToNumeric(), + 1))

但我收到:

error spc0026: Formula 'max( val( EmbaCod ) ) ' cannot be evaluated in this program.

也尝试过:

&EmbaCods = DpEmbalagens()
for &P0126 in &EmbaCods order (&P0126.EmbaCod.ToNumeric())
    &embacod = &P0126.EmbaCod
    exit
endfor

是否有解决此最大字符数的方法?

max aggregate/select 函数仅为属性而不是表达式定义。

解决方法是在定义 EmbaCod 的同一事务中定义数值公式:

EmbaCodFor 类型 Numeric(...) 公式 EmbaCod.ToNumeric()

然后在您的代码中使用

&embacod = str(max(EmbaCodFor))