我怎样才能让 SQL Developer/SQL+ 对于在单个语句中多次出现的替换变量只提示一次?
我有一个大致如下的查询:
select *
from A_TABLE
where A_COLUMN = '&aVariable'
union
select *
from A_TABLE
where B_COLUMN = '&aVariable';
但是当我运行它时,SQL Developer 提示我输入该变量两次,即使它是同一个变量。
如果有办法让它对使用两次的变量只提示一次,我该怎么做?
我不想想要使用脚本,它必须是单个可执行查询。
I have a query roughly like this:
select *
from A_TABLE
where A_COLUMN = '&aVariable'
union
select *
from A_TABLE
where B_COLUMN = '&aVariable';
But when I run it, SQL Developer prompts me for the variable twice, even though it's the same variable.
If there's a way to make it prompt only once for a variable that is used twice, how do I do it?
I do not want to use a script, it must be a single executable query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当我撰写这篇文章时,我想出了如何做到这一点:
然后 SQL Developer 将提示输入绑定变量,您可以输入它并点击“应用”。
As I was forming this post, I figured out how to do it:
SQL Developer will then prompt for a bind variable, you can enter it and hit apply.
请注意第二个(及后续)变量将如何使用双与号 (&&)
Notice how the 2nd (and subsequent) variables will use double-ampersand (&&)
我知道您找到了另一种方法来做到这一点,但仅供参考,基本答案是,如果您将 & 符号加倍(例如,使用“&&aVariable”),那么您为替换变量输入的值将被记住您的会话长度。 请注意,在这种情况下,如果您重新执行查询,将不会再次提示您,它将继续使用相同的值。
I know you found another way to do it, but FYI the basic answer is that if you double up the ampersand (e.g., use '&&aVariable'), then the value you enter for the substitution variable will be remembered for the length of your session. Note that in this case if you re-execute the query you will not be prompted again, it will keep using the same value.
所以当你使用 & 替换你只是使用单个 & 作为一种更快的方法,而不必重新输入值。 通过使用 && 该值被锁定到变量名。 因此 &&variable 与 &&variable1 不同。 通过这种方式,系统将提示您一次,并且您输入的值将附加到该变量名称中。 简单地说,如果您像这样编写代码:
那么如果您想使用一组不同的值,则必须将变量名称更改为类似“&&aVariable3”和“&&aVariable4”的内容足以用于另一组。
So when you use & substitution you are just using the single & as a faster way instead of having to type a value over again. By using the && the value becomes locked-in to the variable name. So &&variable would be different from &&variable1. By doing it this way you will be prompted once and that value you inputted will be adhered to that variable name. Simply put if you write your code like this:
Then if you wanted to use a different set of values you will have to change the variable name to something like this '&&aVariable3' and '&&aVariable4' should be sufficient for another set.