我现在碰到一个问题:
我用user2登录,编写一存储过程proc1。在proc1里,我访问另外一个用户user1的表user1.table1。之后,编译存储过程proc1时报“表或视图不存在”。我该怎么写?
请高手指点,谢谢!前提:user1用户和user2用户都有DBA权限,而且在存储过程外,直接用一段PL-SQL访问另一个用户的表user1.table1时,是可以访问到的。我曾经通过建同义词的方式给user1.table1建一个同义词,用user2访问时,如果直接select,可以访问,但在存储过程中,还是不能访问。
CREATE OR REPLACE procedure proc1 AS
counter int;
BEGIN
select count(*) into counter from user1.table1;
commit;
END proc1;
/
我用user2登录,编写一存储过程proc1。在proc1里,我访问另外一个用户user1的表user1.table1。之后,编译存储过程proc1时报“表或视图不存在”。我该怎么写?
请高手指点,谢谢!前提:user1用户和user2用户都有DBA权限,而且在存储过程外,直接用一段PL-SQL访问另一个用户的表user1.table1时,是可以访问到的。我曾经通过建同义词的方式给user1.table1建一个同义词,用user2访问时,如果直接select,可以访问,但在存储过程中,还是不能访问。
CREATE OR REPLACE procedure proc1 AS
counter int;
BEGIN
select count(*) into counter from user1.table1;
commit;
END proc1;
/
grant select on table1 to user2
该类权限可由两种形式。
1、select any table
该权限为系统权限,表示用户可以select 所有人的表。
conn / as sysdba;
grant select any table to user1; user1用户就能select任何schema的表了。
2、select on object
如果不想让用户访问所有人的表,而规定只能访问某一个用户下的某一个表
conn / as sysdba
create user test1 identified by test1
grant create session to test
grant select on user.table(column) to test1
user表示用户名
table 表示表名
column表示字段名
我权限都赋了。编译存储过程时还是报“无效表名...”。而且我在存储过程外直接select时,是可以访问另外那个用户的表的。很怪。
关键在于编译通不过。我用的是TOAD 7.5.2。
Line: 197
Text: select count(*) into p_ErrorCode from kfdl.as_sy_sbsyjl t;Error: PL/SQL: SQL Statement ignored
Line: 197
Text: select count(*) into p_ErrorCode from kfdl.as_sy_sbsyjl t;