TECH
QUESTION
자주하는 질문답변 입니다.
Oracle
작성자 | 유건데이타 | 등록일 | 2015-08-14 |
제목 | (DBMS_SQL)한 Schema의 모든 table에 대한 privilege를 부여하는 프로시저 | ||
---|---|---|---|
(DBMS_SQL)한 Schema의 모든 table에 대한 privilege를 부여하는 프로시저
===================================================================== 한 Schema의 모든 table에 대한 privilege를 부여하는 프로시저로, DBMS_SQL을 이용해서 구현했다. 첫번 째 input argument로 'select', 'insert', 'update'...와 같은 privilege를 받고, 두번 째 argument로는 권한을 부여할 schema를 받는다. 실행 예) exec grant_on_table('select', 'to_user'); 실행 결과는 이 프로시저를 실행한 Schema에서 select * from user_tab_privs;를 통해 확인해 볼 수 있다. create or replace procedure grant_on_table (privs in varchar2, user_name in varchar2) as cursor1 integer; cursor2 integer; t_name varchar2(30); rows_proces1 integer; rows_processed integer; begin cursor1 := dbms_sql.open_cursor; cursor2 := dbms_sql.open_cursor; dbms_sql.parse (cursor1, 'select table_name from user_tables', dbms_sql.v7); dbms_sql.define_column (cursor1, 1, t_name, 30); rows_processed := dbms_sql.execute (cursor1); loop if dbms_sql.fetch_rows (cursor1) > 0 then dbms_sql.column_value (cursor1, 1, t_name); dbms_sql.parse(cursor2,'grant '|| privs ||' on '|| t_name || ' to ' || user_name,dbms_sql.v7); rows_proces1 := dbms_sql.execute(cursor2); else exit; end if; end loop; dbms_sql.close_cursor (cursor2); dbms_sql.close_cursor (cursor1); EXCEPTION WHEN OTHERS THEN dbms_output.put_line(sqlerrm); if dbms_sql.is_open (cursor1) then dbms_sql.close_cursor (cursor1); end if; END; |
Comment | |||
---|---|---|---|
등록된 코멘트가 없습니다. |