gpt4 book ai didi

sql - 准备好的语句中的重复参数

转载 作者:行者123 更新时间:2023-12-04 17:11:35 29 4
gpt4 key购买 nike

考虑一个看起来像这样的查询:


my $query=<<QUERY;

select * from foo1 where col < ?
union all
select * from foo2 where col < ?
QUERY


假设实际查询确实需要联合并且无法通过其他方式有效解决。 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!

关于sql - 准备好的语句中的重复参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10539574/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com