gpt4 book ai didi

sql - 如何将权限授予 Oracle SCHEMA 上的 ROLE

转载 作者:行者123 更新时间:2023-12-01 10:59:11 27 4
gpt4 key购买 nike

我如何在 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;

这段代码有什么问题?

最佳答案

CREATE SCHEMA是一条语句创建多个对象,需要去掉分号。此外,CREATE SCHEMA 仅支持表、 View 和授权。您需要将 CREATE ROLECREATE 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;
/

关于sql - 如何将权限授予 Oracle SCHEMA 上的 ROLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12875545/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com