我如何在SCHEMA的所有表格上为ROLE
授予某些特权?
我写了这段代码,但是在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;
此代码有什么问题?
答案 0 :(得分:6)
CREATE SCHEMA
是创建多个对象的单个语句,您需要删除分号。此外,CREATE SCHEMA
仅支持表,视图和授权。您需要将CREATE ROLE
和CREATE USER
移出声明。以下是manual:
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;
/
答案 1 :(得分: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 ;
希望有所帮助。