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