存储过程实现模糊查询 多条数据的

为什么代码调试显示游标无效

create or replace procedure ss(

bn in book_lab.bookname%type)

as

ccc book_lab%rowtype;

cursor c_l is

 (select * from book_lab where bookname like '%'||'bn'||'%');

begin

    loop

    fetch c_l into ccc;

            exit when c_l%notfound ;

            dbms_output.put_line (ccc.bookname);

    end loop;

end ss;

调试语句

begin

ss('bn');

end;

 建的表是book_lab
有的属性有
bookid  bookname  writerid

根据你提供的代码,似乎存在一个问题,在游标定义中使用了字符串变量 'bn' 而非传入的参数变量 bn。这会导致查询结果为空,因为无法正确模糊匹配到输入的书名。修改方法如下:

cursor c_l is 
  select * from book_lab where bookname like '%'||bn||'%';

同时,你可以在代码中增加一些错误处理来跟踪问题所在,如:

begin

  ss('The Lord of the Rings');

exception
  when others then
    dbms_output.put_line(SQLERRM);

end;

这样可以在调试时输出问题所在的具体错误信息,帮助你更好地排查和解决问题。