允许用户从表中进行选择

时间:2011-10-22 03:12:29

标签: sql oracle oracle10g ora-00942

cis605确实存在emp表,我想为用户分配权限。对我做错了什么想法?

SQL> grant select on emp to user;

     Grant succeeded.

     SQL> connect user
     Enter password:
     Connected.
     SQL> select * from emp;
     select * from emp
                   *
     ERROR at line 1:
     ORA-00942: table or view does not exist

我也尝试过不同的方式

     SQL> connect cis605
     Enter password:
     Connected.
     SQL> grant select on system.emp to chap7;
     grant select on system.emp to chap7
                             *
     ERROR at line 1:
     ORA-00942: table or view does not exist

继承我应该使用的陈述

SQL> SELECT * from cis605.emp;

1 个答案:

答案 0 :(得分:2)

在第一种情况下它不起作用,因为你需要:

  1. 引用表名,包括它所在的模式。即

    SELECT * FROM schema.EMP;

  2. OR
    2.创建[public]同义词,以便能够“看到”表而不在每个SQL语句中包含模式。


    在第二种情况下,您尝试引用架构,但得到错误的架构。 EMP表通常位于SCOTT模式中,而不是SYSTEM中。虽然在你的情况下,你可能需要这样做:

    grant select on cis605.emp to chap7;
    

    此外,让用户称为“USER”是一个坏主意 - 它是一个Oracle关键字。 (虽然我猜这可能只是出于举例的目的)