简体   繁体   English

InterBase中带文字的联合查询

[英]Union query with literals in InterBase

I have just started using Interbase and I am trying to run the simple query. 我刚刚开始使用Interbase,正在尝试运行简单的查询。 When I have 'SEQUENCE' (or 'INDEX' or 'something') in BOTH part of union query it works fine, but when I have different strings in two parts of the query it produces an error: 当我在联合查询的两个部分都具有“ SEQUENCE”(或“ INDEX”或“某物”)时,它可以正常工作,但是当我在查询的两部分中具有不同的字符串时,它会产生错误:

Data type unknown. 数据类型未知。

select rdb$generator_name as name, 'SEQUENCE' as typ from rdb$generators 
where upper(rdb$generator_name) like '%RD%' 
union all 
select rdb$index_name as name, 'INDEX' as typ from rdb$indices 
where upper(rdb$index_name) like '%RD%';

Therefore, the question is: how could I specify the type or what other thing I could do to run the query? 因此,问题是:我如何指定类型或可以做其他什么来运行查询?

Thanks in advance 提前致谢

We can solve it using type casting: 我们可以使用类型转换解决它:

select rdb$generator_name as name, cast('SEQUENCE' as varchar(10)) as typ from rdb$generators
where upper(rdb$generator_name) like '%RD%' 
union all 
select rdb$index_name as name, cast('INDEX' as varchar(10)) as typ from rdb$indices
where upper(rdb$index_name) like '%RD%';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM