使用带有“的变量”;如“%”;(例如PL/SQL中的“变量%”)?

使用带有“的变量”;如“%”;(例如PL/SQL中的“变量%”)?,sql,oracle,plsql,sqlplus,Sql,Oracle,Plsql,Sqlplus,这个问题类似于在SQL*PLUS中使用LIKE,其中select语句包含一个LIKE子句,如下所示: select * from sometable where somecolumn LIKE 'something%'; 如何在光标中使用相同的内容?我尝试使用以下方法: cursor c is select * from sometable where somecolumn like 'something%'; 同上 编辑:我需要获取一些东西作为参数,这意味着select语句在存储过程中

这个问题类似于在SQL*PLUS中使用LIKE,其中select语句包含一个LIKE子句,如下所示:

select * from sometable where somecolumn LIKE 'something%';
如何在光标中使用相同的内容?我尝试使用以下方法:

 cursor c is select * from sometable where somecolumn like '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子句中使用。

根据我对您的问题的理解,您正在引号中使用变量
搜索。将变量置于引号之外,例如:

 create or replace procedure PROC1(search VARCHAR2) 
 IS
  cursor test_cur(search IN VARCHAR2)
   IS
    SELECT student_name 
    FROM student
    WHERE student_name LIKE search||'%'; --you're putting you variable within quotes

 v_temp_var student.student_name%TYPE;

BEGIN

 OPEN test_cur(search);
  LOOP
   FETCH test_cur INTO v_temp_var;
    EXIT WHEN test_cur%NOTFOUND;

    DBMS_OUTPUT.PUT_LINE(v_temp_var);  
  END LOOP;

 CLOSE test_cur;

END test;

所以你试过了。。。发生了什么?你确定这是原因吗<代码>光标x是{select}
应该是有效的,其中
{select}
表示任意的select DQL。我得到一个变量,作为一个参数,并在光标内使用它。请发布一个完整(但最小)的上下文,说明其他人可以尝试的错误。我认为这种简化缺少一个重要部分<代码>'something%'只是一个文字;没有涉及变量。post和报告的错误消息与意图不一致。我已经更新了标题,给它一些指导。在您能够使用“正常”选择之前,担心光标是没有意义的。