如何在Oracle PL/SQL where子句中使用变量 [英] How to use variables in an Oracle PL/SQL where clause
问题描述
我似乎无法使变量在Oracle PL/SQL where子句中工作.我来自Microsoft SQL Server背景,这很容易.例如,执行类似于以下操作的所有步骤将是什么?
I can't seem to get variables to work in an Oracle PL/SQL where clause. I come from a Microsoft SQL Server background and there it was easy. For example, what would be all steps needed to do something similar to the following?
declare @var int set @var = 1
select * from SomeTable where SomeField = @var
在PL/SQL中这似乎不应该很难,但是显然可以. :-/听说我需要在PL/SQL中使用游标等?
This doesn't seem like it should be hard in PL/SQL, but evidently it is. :-/ I hear I need to use cursors and the like in PL/SQL?
任何帮助将不胜感激.谢谢.
Any help would be greatly appreciated. Thanks.
推荐答案
您要如何处理SELECT返回的数据?如果您只想查看它,则根本不需要PL/SQL,只需在SQL Plus中执行此操作:
What do you want to do with the data that the SELECT returns? If you just want to see it you don't need PL/SQL at all, just do this in SQL Plus:
variable var number
exec :var := 1
select * from SomeTable where SomeField = :var;
或者在SQL Developer或Toad之类的工具中,只需执行以下操作:
Or in a tool like SQL Developer or Toad, just do this:
select * from SomeTable where SomeField = :var;
,它会提示您输入:var的值.
and it will prompt you to enter the value for :var.
这篇关于如何在Oracle PL/SQL where子句中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!