SYSTEMTI.NET

Please or Cadastrar to create posts and topics.

GRANT para TODAS as tabelas do schema

Olá, pessoal. Compartilhar com vocês um script que automatiza o GRANT para as tabelas de um determinado SCHEMA.

Query bastante útil para liberação de acesso para novos usuários. Deixo abaixo scripts.

--TABELAS, VIEWS
BEGIN
FOR R IN (SELECT owner, object_name FROM ALL_OBJECTS WHERE owner='DBAPORTAL' and object_type = 'TABLE') LOOP
EXECUTE IMMEDIATE 'grant select on '||R.owner||'.'||R.object_name||' to USER_BI';
END LOOP;
END;

BEGIN
FOR R IN (SELECT owner, object_name FROM ALL_OBJECTS WHERE owner='DBAPORTAL' and object_type = 'VIEW' AND STATUS ='VALID') LOOP
EXECUTE IMMEDIATE 'grant select on '||R.owner||'.'||R.object_name||' to USER_BI';
END LOOP;
END;
SELECT * FROM ALL_OBJECTS WHERE owner='DBAMV' and object_type = 'VIEW'

 

--FUNCTION, PROCEDURE, PACKAGE
BEGIN
FOR R IN (SELECT owner, object_name
FROM ALL_OBJECTS WHERE owner='DBAPORTAL' and object_type = 'FUNCTION') LOOP
EXECUTE IMMEDIATE 'grant execute on '||R.owner||'.'||R.object_name||' to USER_BI';
END LOOP;
END;

BEGIN
FOR R IN (SELECT owner, object_name
FROM ALL_OBJECTS WHERE owner='DBAPORTAL' and object_type = 'PROCEDURE') LOOP
EXECUTE IMMEDIATE 'grant execute on '||R.owner||'.'||R.object_name||' to USER_BI';
END LOOP;
END;

BEGIN
FOR R IN (SELECT owner, object_name
FROM ALL_OBJECTS WHERE owner='DBAPORTAL' and object_type = 'PACKAGE') LOOP
EXECUTE IMMEDIATE 'grant execute on '||R.owner||'.'||R.object_name||' to USER_BI';
END LOOP;
END;

 

Espero que lhe seja útil.

Se você deseja apoiar o desenvolvimento do SYSTEMTI.NET, você pode compartilhar algum conteúdo no fórum ou doar. Muito obrigado !