使用过程创建视图时,oracle的权限不足

时间:2016-03-08 08:21:45

标签: sql oracle view procedure create-view

当调用应创建视图的过程时,它会返回"权限不足"。我可以使用SQL命令本身创建视图,但不能在运行过程时创建。完成的所有操作都在架构所有者中。请让我知道如何解决这个问题。

/* 1. FIRST, I LOGON TO MY OWN SCHEMA, CALLED 'MY_SCHEMA' */
/* (IF YOU WANT TO USE A DIFFERENT ONE, JUST REPLACE THE TEXT MY_SCHEMA WITH YOUR OWN SCHEMA NAME) */

/* 2. DROP THE EXAMPLE TABLE IF IT ALREADY EXISTS */
DECLARE TBL_COUNT INT;
BEGIN
  SELECT COUNT(*) INTO TBL_COUNT FROM ALL_TABLES WHERE OWNER = 'MY_SCHEMA' AND TABLE_NAME = 'EXAMPLE';
  IF TBL_COUNT > 0 THEN
    EXECUTE IMMEDIATE('DROP TABLE "MY_SCHEMA"."EXAMPLE"');
  END IF;
END;
/
-- Result : Done

/* 2. CREATE THE EXAMPLE TABLE */
CREATE TABLE MY_SCHEMA.EXAMPLE
(
  COL1 INTEGER
);
-- Result : Done 

/* 3. THEN, CREATE A VIEW IN MY OWN SCHEMA, WHICH POINTS TO THE TABLE IN MY OWN SCHEMA */
CREATE OR REPLACE VIEW MY_SCHEMA.VW_EXAMPLE AS SELECT * FROM MY_SCHEMA.EXAMPLE;
-- Result : Done 

/* 4. DROP THE VIEW, JUST FOR ARGUMENT'S SAKE */
DROP VIEW MY_SCHEMA.VW_EXAMPLE;
-- Result : Done 

/* 5. NOW CREATE A PROCEDURE IN MY OWN SCHEMA, WHICH CREATES A VIEW IN MY OWN SCHEMA, WHICH POINTS TO A TABLE IN MY OWN SCHEMA */
CREATE OR REPLACE PROCEDURE MY_SCHEMA.PRC_EXAMPLE AS
BEGIN
  EXECUTE IMMEDIATE 'CREATE OR REPLACE VIEW MY_SCHEMA.VW_EXAMPLE AS SELECT * FROM MY_SCHEMA.EXAMPLE';
END;
-- Done

/* 6. LET'S CALL THE PROCEDURE FROM MY OWN SCHEMA, WHICH SHOULD CREATE THE VIEW IN MY OWN SCHEMA, POINTING TO A TABLE IN MY OWN SCHMEA */
BEGIN
  MY_SCHEMA.PRC_EXAMPLE;
END;
-- ORA-01031 : Insufficient privileges

1 个答案:

答案 0 :(得分:0)

用户MY_SCHEMA有哪些特权?

在过程(或PL / SQL块)内部仅应用直接授予权限。角色授予的权限(例如角色DBARESOURCE)不适用于过程或PL / SQL块。