oracle 中查询动态字段的问题

来源:百度知道 编辑:UC知道 时间:2024/05/13 19:50:41
oracle 存储过程中 怎么实现

select * from table where a='1'
a是动态的

procedure proc_test1
is
cursor cursor_a is --声明游标(将TABLE中的所有A列的值放入游标中)
select a
from table
v_id table.id%type; --声明v_id的数据类型
begin
open cursor_a; --打开游标
loop --循环读取游标中的A列的值,并让a=v_id.
fetch cursor_a into v_id;
select *
from table
where a='1'
and a=v_id
exit when cursor_a%notfound;--读完退出
end loop;
close cursor_a; --关闭游标
end;

上面的过程中我没写查询完以后select *放入的游标,只是将a是动态的实现,需要的话我再帮你写,多定义个游标就可以了。

不知道我写的你看明白没有,不明白再问我,谢谢!