【发布时间】:2012-04-26 09:38:15
【问题描述】:
问题类似于在 SQL *PLUS 中使用 LIKE,其中 select 语句包含 LIKE 子句,如下所示:
select * from sometable where somecolumn LIKE 'something%';
如何在光标中使用相同的内容?我尝试使用以下内容:
cursor c is select * from sometable where somecolumn like 'something%';
同上
编辑:我需要将 something 作为参数,这意味着 select 语句在存储过程中执行。
编辑 2:
create procedure proc1 (search VARCHAR) is
cursor c is select student_name from students where student_name like 'search%';
--我知道使用“search%”检索包含“key search”的学生姓名,但有没有其他方法可以使用这样的变量。
do something;
end;
简而言之,我需要选择包含作为参数传递的值的学生姓名;这可能不是全名,但足以在 like 子句中使用。
【问题讨论】:
-
所以……你试过了……发生了什么?
-
您确定是的原因吗?
CURSOR x IS {select}应该是有效的,其中{select}代表任意选择 DQL。 -
我得到一个变量,something作为参数,并在光标内使用它。
-
请发布一个完整(但最少)的上下文,说明其他人可以尝试的错误。我相信这个简化中缺少一个重要的部分。
'something%'只是文字;不涉及任何变量。 -
帖子和报告的错误消息和意图不一致。我已经更新了标题给它一些方向。在您能够使用“正常”SELECT 完成之前,无需担心 CURSOR。