Use a variable with "LIKE%" (for example, "variable%") in PL / SQL?

The question is similar to using LIKE in SQL * PLUS , where the select statement contains the LIKE clause as follows:

select * from sometable where somecolumn LIKE 'something%';

How can the same thing be used inside the cursor? I tried using the following:

 cursor c is select * from sometable where somecolumn like 'something%'; 

as stated above

EDIT: I need to get something as a parameter, that is, the select statement is executed in the stored procedure.

EDIT 2:

create procedure proc1 (search VARCHAR) is

cursor c is select student_name from students where student_name like 'search%';

- I know that “search%” retrieves student names containing “search for key”, but is there any other way to use such a variable.

do something;

end;

, , , ; .

+5
1

search . , :

 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;
+20

All Articles