提供授权的过程,无效的表名称错误

时间:2017-02-06 14:13:42

标签: oracle stored-procedures plsql database-metadata execute-immediate

我正在尝试创建一个为特定架构对象提供授权的过程。过程似乎编译正常,但它在执行时出错。

这个简单的程序出了点问题,但我找不到原因。

步骤:

create or replace procedure ch.grants_to_schema_objects(
          i_target_schema varchar2, 
          i_target_user varchar2) as
begin
 for mt in (SELECT 'GRANT SELECT ON ' || chr(39) 
              || i_target_schema || chr(39) 
              || '.' || TABLE_NAME || ' TO ' || chr(39) 
              || i_target_user || chr(39)
              || ' WITH GRANT OPTION' as grnt 
          FROM ALL_TABLES 
          WHERE OWNER = i_target_schema) loop
  dbms_output.put_line(mt.grnt);
  execute immediate mt.grnt;
end loop;
end;

致电:

 execute ch.grants_to_schema_objects('SR', 'CH');

错误:

ORA-06512: "CH.GRANTS_TO_SCHEMA_OBJECTS", line 5
ORA-06512: line 1
00903. 00000 -  "invalid table name"
*Cause:    
*Action:

1 个答案:

答案 0 :(得分:0)

CHR(39)打破了它。将其替换为CHR(34)"您需要将用户名分开,而不是'