原文链接:www.gbase.cn/community/p...
更多精彩内容尽在南大通用GBase技术社区,南大通用致力于成为用户最信赖的数据库产品供应商。
问题现象
to_number和decimal列关联时报错,报错内容如下:
sql
ERROR 1149 (42000): (GBA-02SC-1001) Data types of equivalence join relation ((to_number(`a`.`a`) = `b`.`a`)) are not supported , data types: left is DOUBLE, right is DECIMAL(22,0)
具体复现过程:
sql
gbase> create table t_to_number_dec(a decimal(22,0));
Query OK, 0 rows affected (Elapsed: 00:00:02.04)
gbase> create table t_to_number_varchar(a varchar(10));
Query OK, 0 rows affected (Elapsed: 00:00:00.12)
gbase> insert into t_to_number_dec values (111111);
Query OK, 1 row affected (Elapsed: 00:00:00.39)
gbase> insert into t_to_number_varchar values ('111111');
Query OK, 1 row affected (Elapsed: 00:00:00.35)
gbase> select * from t_to_number_varchar a join t_to_number_dec b on to_number(a.a) = b.a;
ERROR 1149 (42000): (GBA-02SC-1001) Data types of equivalence join relation ((to_number(`a`.`a`) = `b`.`a`)) are not supported , data types: left is DOUBLE, right is DECIMAL(22,0)
解决方案:
修改gbase_to_number_str2dec为1,修改后执行情况如下:
sql
gbase> set gbase_to_number_str2dec = 1;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> select * from t_to_number_varchar a join t_to_number_dec b on to_number(a.a) = b.a;
+--------+--------+
| a | a |
+--------+--------+
| 111111 | 111111 |
+--------+--------+
1 row in set (Elapsed: 00:00:00.12)
附:gbase_to_number_str2dec参数含义:
to_number函数在处理字符串时,转换后的类型时,参数值为0时转换成double类型,参数值为1时,转换成decimal(65,30)类型。
默认值:'OFF,0
最小值:'OFF',0
最大值:ON',1
级别: global、session
原文链接:www.gbase.cn/community/p...
更多精彩内容尽在南大通用GBase技术社区,南大通用致力于成为用户最信赖的数据库产品供应商。