数据库中有user_tab_columns和user_tables这两个表,你看看,可以解决的你问题.肿么没分
表1查出来 后台把数据插到list或者map里传给jsp jsp的foreach遍历显示在action form表单提交可以获取action中数据
弄个字符串变量,设个游标,用括号里那一串;
然后遍历表名,每找到一个表名,就在字符串变量里拼上一段:=
'select
*
from
'||table_name||';',
然后用EXECUTE
IMMEDIATE执行;
然后读下一个表名,直至遍历完毕.
大致就是这么个意思.
不知道你是写程序用,还是找数据用.写程序的话,一步到位,可能比较复杂!
下面附一点找数据的较笨的方法!看对你有没有用,以用户SCOTT为例:
①dba_tab_columns有某个用户的所以表和列等信息:select table_name,column_name from dba_tab_columns where owner='SCOTT'
set serveroutput on
delete from scott.TCOL;
commit;
declare
cursor my_cursor is
select table_name,column_name from dba_tab_columns where owner='SCOTT' and DATA_TYPE='NUMBER';
begin
open my_cursor;
loop
fetch my_cursor into v_table,v_col;
dbms_output.put_line(v_table);
exit when my_cursor%NOTFOUND;
v_sql:='Insert into SCOTT.TCOL(A,B) select '||''''|| v_table||''''||','||''''|| v_col||''''||' from SCOTT.'||v_table||' where '||v_col||'=1100';
dbms_output.put_line(v_sql);
EXECUTE IMMEDIATE v_sql;
end loop;
close my_cursor;
end;
以上仅参考!
cursor t_name is select teachername from teacher---------申明游标t_name为从teacher表中查询老师名字
open t_name;------打开游标t_name
loop-------开始循环(遍历)
fetch t_name into teacher_name-------将老师名字值赋予变量teacher_name
if t_name%found-------------开始遍历有值时插入以下数据
then
select name,count(*) into new_table
from table_teacher_student
where name=teacher_name group by name-----将一个老师名字依据条件插入新表数据
else
dmbs_output.put_line('完成所有工作');---------遍历结束时输出完成工作
exit;
end if;
仓促写下以上内容,可能部分语法报错,思路就是这样,很基本的一个游标使用.
写个for循环就可以遍历一遍,例如meminfo 表中有member_id 你现在有的id需要在meminfo 中查询出现次数
for rec in(select member_id from meminfo) loop
if member_id=id
then i:=i+1;
end if;
这样就会遍历一遍你的这个数据库