我的 Advantage 数据库中有类似的内容:-
drop table #test;
create table #test (x cichar(50));
insert into #test (x) values ('cheese');
insert into #test (x) values ('fromage');
insert into #test (x) values ('Queso');
select
t1.x t1_x,
t2.x t2_x
from
#test t1
inner join
(
select
'CHEESE' x // String literal will be of type VARCHARFOX
from
system.iota
) t2
on t1.x=t2.x
这给了我信息:-
poQuery: Error 7200: AQE Error: State = HY000; NativeError = 2213; [iAnywhere Solutions] [Advantage SQL Engine]Invalid comparison or operation on strings with different collations. ** Script error information: -- Location of error in the SQL statement is: 137 (line: 5 column: 1)
当我想:-
t1_x t2_x
cheese CHEESE
这是因为 'CHEESE' 字符串字面值变成了 VARCHARFOX 类型,而临时表中的列是 cichar 类型,因为我想要不区分大小写的比较。
我可以通过在比较中添加“COLLATE ads_default_ci”来修复此实例,但这很麻烦,而且我永远记不起它的确切语法。
我想我一定是在列类型或数据库配置方面做了一些根本性的错误,这样做的优雅/正确方法是什么?
最佳答案
这里的问题不是字符串文字,字符串文字通常表现得很好。
他们得到 the COERCION_COMPATBILE collation :
TRY drop table #test; CATCH ALL END TRY;
create table #test (x cichar(50));
insert into #test (x) values ('cheese');
insert into #test (x) values ('fromage');
insert into #test (x) values ('Queso');
select
t1.x t1_x,
'CHEESE' t2_x
from
#test t1
where
t1.x='CHEESE'
问题是您正在引入派生表,ADS 引擎将派生表字段的数据类型确定为VARCHARFOX(6)
:
select
'CHEESE' x
from
system.iota
我不认为有一种简单的方法可以做到这一点。
我创建了 an upstream request on the ADS forum .
我还添加了一个 feature request基于此。如果实现,解决方案将是:
select
CICHAR'CHEESE' x
from
system.iota
我认为这是一个干净的解决方案。
您还应该注意其他事项:
有一个整理 associated with each connection .
NCHAR 还内置了对区分大小写的和不区分大小写排序规则的支持。使用哪一个取决于当前连接的排序规则。
您可以使用 AdsSetCollation 为当前连接设置排序规则功能(或者它对您的开发环境来说是等效的,例如在 ARC 中,您可以在连接属性中设置它)。
关于sql - Advantage 数据库、区分大小写和排序规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27440632/