3

我如何ROLE在 SCHEMA 的所有表上授予 a 一些权限?
我写了这段代码,但是在 SQLDeveloper 中它给出了一个错误。

CREATE SCHEMA AUTHORIZATION alberto;

CREATE TABLE Cucine (
  tipo varchar(1) primary key,
  descrizione varchar(200) not null
);

CREATE TABLE Quartieri (
  codice varchar(4) primary key,
  nome varchar(100) not null
);

CREATE TABLE Ristoranti (
  codice varchar(5) primary key,
  nome varchar(150) not null,
  indirizzo varchar(250),
  tipocucina varchar(1) references Cucine(tipo),
  codquart varchar(4) references Quartieri(codice)
);

CREATE TABLE CarteDiCredito (
  codcircuito varchar(4) primary key,
  nomecircuito varchar(100) not null
);

CREATE TABLE Convenzioni (
  circuito varchar(4) references CarteDiCredito(codcircuito),
  codristorante varchar(5) references Ristoranti(codice),
  primary key(circuito, codristorante)
);

CREATE ROLE turista;
GRANT SELECT ON ENTE_TURISTICO.* TO turista;
CREATE USER DBAEnte IDENTIFIED BY 12345;
CREATE USER vinni IDENTIFIED BY mosh;
GRANT dba TO DBAEnte;
GRANT turista TO vinni;

这段代码有什么问题?

4

2 回答 2

6

CREATE SCHEMA是单个语句创建多个对象,需要去掉分号。此外,CREATE SCHEMA仅支持表、视图和授权。您需要将CREATE ROLEandCREATE USER移出语句。这是手册中的一个示例:

CREATE SCHEMA AUTHORIZATION oe
   CREATE TABLE new_product 
      (color VARCHAR2(10)  PRIMARY KEY, quantity NUMBER) 
   CREATE VIEW new_product_view 
      AS SELECT color, quantity FROM new_product WHERE color = 'RED' 
   GRANT select ON new_product_view TO hr; 

要授予SELECT所有表,您需要像这样的动态 SQL:

begin
  for tables in (select table_name from all_tables where owner = 'ALBERTO') loop
    execute immediate
      'grant select on alberto.'||tables.table_name||' to turista';
  end loop;
end;
/
于 2012-10-13T18:18:53.063 回答
0

使用以下代码:-

CREATE TABLESPACE dwtblspc LOGGING DATAFILE 'D:\oraclexe\app\oracle\oradata\XE\DWTBLSPC.DBF' SIZE 300M AUTOEXTEND ON NEXT 1048K MAXSIZE UNLIMITED;

CREATE USER prateek IDENTIFIED by prateek DEFAULT TABLESPACE dwtblspc ACCOUNT UNLOCK;

GRANT unlimited tablespace to prateek ;

CREATE ROLE prateek_role;

GRANT CREATE SESSION,ALTER SESSION,CREATE TABLE,CREATE CLUSTER,CREATE SYNONYM,CREATE VIEW,CREATE SEQUENCE,
CREATE DATABASE LINK,CREATE PROCEDURE,CREATE TRIGGER,CREATE TYPE,CREATE OPERATOR,CREATE INDEXTYPE,BACKUP ANY TABLE,
SELECT ANY TABLE,CREATE ANY TABLE,CREATE ANY INDEX,ALTER ANY INDEX,ALTER ANY INDEXTYPE,DROP ANY INDEX,DROP ANY INDEXTYPE to prateek_role;

GRANT prateek_role to prateek ;

希望它有所帮助。

于 2014-09-03T16:18:25.057 回答