简体   繁体   English

ORA-01031 创建视图时权限不足?

[英]ORA-01031 Insufficient privileges while CREATING a VIEW?

When I try to create a view that including different tables I'm getting the following error: Error at Line 1: ORA-01031 Insufficient privileges.当我尝试创建包含不同表的视图时,出现以下错误:第 1 行错误:ORA-01031 权限不足。

Could anyone tell me what could be the problem.谁能告诉我可能是什么问题。 I tried following the another stackoverflow post mentioned here but it's pertaining to different schemas.我尝试遵循此处提到的另一篇 stackoverflow 帖子,但它与不同的模式有关。

ORA-01031: insufficient privileges when selecting view ORA-01031: 选择视图时权限不足

Please let me know as I'm new here.请让我知道,因为我是新来的。

My Query is as follows:我的查询如下:

ORiginal Question:Create a view to select employee ID, employee name, hire date, and department number.原始问题:创建一个视图来选择员工 ID、员工姓名、雇用日期和部门编号。

MY SOLUTION:我的解决方案:

CREATE VIEW SIMPVIEW AS
SELECT EMPNO, ENAME, HIREDATE,DEPTNO
FROM EMP;

Then probably you may not have the privileges to perform the CREATE VIEW command in your database schema... Log in into SYSDBA account and issue the command那么您可能没有权限在您的数据库模式中执行CREATE VIEW命令...登录到 SYSDBA 帐户并发出命令

GRANT CREATE VIEW TO <dbusername>;

Here <dbusername> should be replaced with the name of the user you want to give access to the CREATE VIEW command.此处的<dbusername>应替换为您希望授予CREATE VIEW命令访问权限的用户的名称。

You can check if your user has VIEW creation privileges using select * from session_privs .您可以使用select * from session_privs来检查您的用户是否具有VIEW创建权限。

Note that to be able to create a view, the user that is creating it needs to have been granted SELECT privileges on all the objects being used, as well as the mentioned CREATE VIEW privilege.请注意,为了能够创建视图,创建它的用户需要被授予对所有正在使用的对象的SELECT权限,以及提到的CREATE VIEW权限。 You can also check that by querying to USER_TAB_PRIVS with the user getting the error.您还可以通过查询USER_TAB_PRIVS来检查用户是否收到错误。

when I wanted to execute the above query in sql developer I faced issues as I did not have enough privileges to create a view or other oracle object schema such as trigger, packages, procedures etc. I found the error to ie “Error at Line 1: ORA-01031 Insufficient privileges”.当我想在 sql developer 中执行上述查询时,我遇到了问题,因为我没有足够的权限来创建视图或其他 oracle 对象模式,例如触发器、包、过程等。我发现错误为“第 1 行错误” : ORA-01031 权限不足”。 so, I needed the all privileges to practice all these queries and programs.所以,我需要所有权限来练习所有这些查询和程序。 I took the following steps in order to solve my problem:我采取了以下步骤来解决我的问题:

  1. As I logged in as a user name 'scott', so my name is 'scott' not 'Dhruv'.由于我以用户名“scott”登录,所以我的名字是“scott”而不是“Dhruv”。 My ambition was to grant all the privileges to me ie to the user 'scott'.我的目标是将所有权限授予我,即用户“scott”。
  2. For that, I need to enter in the database as a DBA.为此,我需要以 DBA 身份进入数据库。 Now, question is!现在,问题是! How to log in as DBA.如何以 DBA 身份登录。 For this, I opened command prompt and I logged in the database as sysdba by following the below steps:为此,我打开命令提示符并按照以下步骤以 sysdba 身份登录数据库:

a) In window run, I typed cmd to open command prompt. a) 在窗口运行中,我输入 cmd 打开命令提示符。 I typed: sqlplus /nolog which means that I logged in without providing required credentials.我输入: sqlplus /nolog 这意味着我在没有提供所需凭据的情况下登录。
b) I authenticated myself for my underlying O/S and entered in database as DBA. b) 我为我的底层操作系统验证了自己的身份,并以 DBA 的身份进入了数据库。 For that, I typed in command prompt: connect / as sysdba;为此,我在命令提示符中输入:connect / as sysdba; c) I evaluated who is the DBA user in my database if exists. c) 如果存在,我评估了谁是我的数据库中的 DBA 用户。 For that I typed: select name from V$database;为此,我输入: select name from V$database; d) Here we go after this command. d) 在这里,我们执行此命令。 I finally granted myself (scott) to create view in sql developer by typing the command: grant create view to scott;我终于允许自己(scott)通过键入以下命令在 sql developer 中创建视图:grant create view to scott; e) Finally, I granted myself all the privileges by typing: grant all privileges to scott; e) 最后,我通过键入以下内容授予自己所有权限:grant all privileges to scott;

Snapshot of command prompt: I have attached.命令提示符的快照:我已附加。

Finally, I executed and created my view: I have attached最后,我执行并创建了我的视图:我已附加

我遇到了这个错误,解决方案是将grant select WITH GRANT OPTION来自视图中包含的另一个模式的表。

  1. At first You need to give the user authentication so you need to know who dba in normal the system give this authentication so make conn system/ *password*首先你需要给用户认证所以你需要知道系统中正常的dba是谁给这个认证所以make conn system/ *password*
  2. give grand or authentication by put grant create view to *DataBaseUsername*;通过 put grant create view to *DataBaseUsername*;给予盛大或认证grant create view to *DataBaseUsername*;
  3. make the connection to your user and apply your command与您的用户建立连接并应用您的命令

You have to give select any table privilege to the user.您必须向用户授予 select any table 权限。 Then the view will compile successfully.然后视图将成功编译。 No need to explicitly grant select to the user to all the objects.无需向用户显式授予对所有对象的选择权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM