注册

C 外部函数 de_return_null() 返回空字符串,没有返回空值

耀耀 2025/08/11 82 0

【DM版本】: DM Database Server 64 V8 8.4 企业版 03134284172-20240823-240363-20093
【操作系统】:麒麟 Kylin Linux Advanced Server V10 (Tercel)
【CPU】: 鲲鹏920
【问题描述】*:
外部函数其中部分如下

de_data rounding2(de_args *args) {

de_data result = de_return_null();

if (de_is_null(args, 0) || de_is_null(args, 1)) {
return de_return_null();
}

char *num_str = de_get_str(args, 0);
if (!num_str) {
return de_return_null();
}

int decimal_places = de_get_int(args, 1);

char *res = internal_rounding(num_str, decimal_places);

de_str_free(num_str);

if (!res || *res == '\0') {
return de_return_null();
}

result = de_return_str(res);

free(res);
res = NULL;

return result;
}

创建外部函数如下:
CREATE OR REPLACE FUNCTION rounding(num VARCHAR, decimal_places INT)
RETURN VARCHAR
EXTERNAL '/home/dmfunc/rounding2.so' "rounding2" USING C;
/

外部函数创建后,执行如下:
SQL> select rounding(NULL, 3) ;

行号 rounding(NULL,3)


1

SQL> select if(rounding(NULL, 3) = '',1,0);

行号 IF(rounding(NULL,3)='',1,0)


1 1

但我需要的是和系统函数round一样的结果,返回null,不是空字符串
SQL> select round(NULL, 3) ;

行号 round(NULL,3)


1 NULL

SQL> select if(round(NULL, 3) = '',1,0);

行号 IF(round(NULL,3)='',1,0)


1 0

达梦数据库de_return_null() 返回空值 是否存在问题?

回答 0
暂无回答
扫一扫
联系客服