--建立唯讀權限帳號
CREATE USER readonly_user
IDENTIFIED BY readonly_user
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp;
IDENTIFIED BY readonly_user
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp;
GRANT CREATE SESSION to readonly_user
--建立JOB,每日00:00 GRANT一次權限
DECLARE
x NUMBER;
BEGIN
SYS.DBMS_JOB.SUBMIT
( job => x
,what => 'BEGIN
FOR i IN (SELECT table_name FROM all_tables WHERE owner='myuser')
LOOP
EXECUTE IMMEDIATE 'GRANT SELECT ON myuser.' || i.table_name || ' TO readonly_user';
END LOOP;
END;'
,next_date => to_date('20/06/2019 00:00:00','dd/mm/yyyy hh24:mi:ss')
,interval => 'null'
,no_parse => FALSE
);
SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
COMMIT;
END;
x NUMBER;
BEGIN
SYS.DBMS_JOB.SUBMIT
( job => x
,what => 'BEGIN
FOR i IN (SELECT table_name FROM all_tables WHERE owner='myuser')
LOOP
EXECUTE IMMEDIATE 'GRANT SELECT ON myuser.' || i.table_name || ' TO readonly_user';
END LOOP;
END;'
,next_date => to_date('20/06/2019 00:00:00','dd/mm/yyyy hh24:mi:ss')
,interval => 'null'
,no_parse => FALSE
);
SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
COMMIT;
END;