我正在寻找一种方法来模拟 SP 中的 Firebird 中的“创建表作为选择”。
我们在另一个产品中经常使用这个语句,因为它很容易制作更小的、可索引的集合,并在服务器端提供非常快速的结果。
create temp table a select * from xxx where ...
create indexes on a ...
create temp table b select * from xxx where ...
create indexes on b ...
select * from a
union
select * from b
或者避免子查询中的三个或更多级别。
select *
from a where id in (select id
from b
where ... and id in (select id from c where))
“create table as select”非常好,因为它提供了正确的字段类型和名称,所以我不需要预定义它们。
我可以用 Delphi 在 Firebird 中模拟“创建表为”:
选择不带行,获取表字段类型,将它们转换为创建表 SQL,运行它,然后“插入临时表”+ 带行的 selectsql(无排序依据)。没关系。
但是我可以在一个通用的存储过程中创建相同的东西来获取一个选择 sql,并用结果创建一个新的临时表吗?
那么:我可以获取查询结果的字段类型,我可以从它们创建字段创建者 SQL 吗?
我只是问是否有办法(然后我必须指定列)。