Oracle 存储过程+游标 实现对输入参数的模糊查询

论坛 期权论坛 脚本     
匿名技术用户   2020-12-30 06:23   31   0

1、首先写一个存储过程

create or replace procedure pro_updateuser
(
a_keyword in Varchar2   --输入查询关键字
)
as
ccc users%rowType;  --用来接查询结果,users是我的表名
cursor c1 is   --定义一个游标c1 ,如下为模糊查询的语句
      select * from users where
      username like '%'||a_keyword||'%' or
      passwd like '%'||a_keyword||'%' or
      name like '%'||a_keyword||'%' or
      sex like '%'||a_keyword||'%' or
      birthday like '%'||a_keyword||'%' or
      email like '%'||a_keyword||'%';
begin
  loop
    if not c1%ISOPEN then
      open c1;
    end if;

    fetch c1 into ccc;
    exit when c1%notfound or c1%notfound is null;
    dbms_output.put_line(ccc.username||' '||ccc.name||' '||ccc.email); 
  end loop;
end;


2、调用

begin
  pro_updateuser('张');  
end;

3、运行结果

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP