How to use variables in an Oracle PL/SQL where clause(如何在 Oracle PL/SQL where 子句中使用变量)
问题描述
我似乎无法让变量在 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 子句中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Oracle PL/SQL where 子句中使用变量
基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
