一个oracle里面有用户 A、 B、 C、 D 、E 密码分别是 A、 B、 C、 D、 E
A、 B、 C、 D 、E用户下各有相同的表 student
我想实现:
         判断各用户下的student表里是否有数据,没有数据则插入一条数据到该表中,
求事例,或者解决思路!

解决方案 »

  1.   

    将A,B,C,D,C用户访问表的权限授予一个用户,如test,然后在test写一段PL/SQL代码判断插入数据就行了
    授予test权限
    grant all on student to test;declare
    cnt number;
    begin
      --判断a用户student表
      select count(*) into cnt from a.student;
      if cnt<=0 then
       --插入数据
       --insert into ....
      end if;
      --判断b用户student表
      .....
    end;
      

  2.   


    --dba用户下:
    declare
          cn number;
    begin
         select count(*) into cn
         from a.student;
         if cn > 0 then
            dbms_output.put_line('a用户下student表中有数据');
         else 
             insert into a.student(col_1,col_2,col_3)
             values (value_1,value_2,value_3);
             commit;
         end if;
    end;
      

  3.   

    如果用户 有5000个用户下面都有student 表,这个语句改怎么写? 
      

  4.   

    大概的代码 其余自己补充下--定义
    strSQL varchar2(4000);
    iCount int;……for r in (select name from user$)--取所有用户
    loop
         strSQL := 'select count(*) from ' || r.name || '.student';
         execute immediate strSQL into iCount;
         if iCount = 0 then
             strSQL := 'insert into ' || r.name || ' values (.......)';
             execute immediate strSQL;
         end if;
    end loop;
    commit;
      

  5.   

    可以先取出所有拥用student表的用户(all_tables视图)再用1、2楼的方法