考虑一个看起来像这样的查询:
my $query=<<QUERY;
select * from foo1 where col < ?
union all
select * from foo2 where col < ?
QUERY
Run Code Online (Sandbox Code Playgroud)
假设实际查询确实需要联合并且不能以另一种方式有效地解决.where子句中的变量将始终相同.有没有什么方法可以构造这个,所以我只需要传递1个参数来执行而不是两次传递相同的参数?
可以尝试以下操作,我假设您将一个整数传递给 where 子句...
DECLARE @variableName as int
SET @variableName = ? --the value gets passed here once
select * from foo1 where col < @variableName -- and gets used here
union all
select * from foo2 where col < @variableName -- and here!
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
868 次 |
| 最近记录: |