생계/Oracle2020. 6. 16. 14:43


뷰를 생성하기위해서는 create view 권한이 필요하다. 

자신의 스키마가 아닌 다른 스키마에 뷰를 생성하기 위해서는 create any view 권한이 필요하다. 


1. grant create view

 

2. view vs any view

 

 

 

 ===  1. grant create view ====

 

create user USER_A identified by "q1w2e3r4";

grant resource to USER_A;

grant connect to USER_A;


exit

 

 

sqlplus USER_A/q1w2e3r4

 

create table USER_A.test_tab(a int);

 

Table created.

 

 

create or replace view USER_A.vw_a

as

select '1' a

from USER_A.test_tab

;

ORA-01031: insufficient privileges

 

exit


sqlplus / as sysdba


grant create view to USER_A;

 

exit

 

sqlplus USER_A/q1w2e3r4

 

create or replace view USER_A.vw_a

as

select '1' a

from USER_A.test_tab

;

View created.

 

exit



===  2. grant create any view ====


sqlplus / as sysdba

 

create user USER_B identified by "q1w2e3r4";

grant resource to USER_B;

grant connect to USER_B;

grant create view to USER_B;

grant select on USER_A.test_tab to USER_B;

 

exit

 

sqlplus USER_B/q1w2e3r4

 

create or replace view USER_B.vw_a

as

select '1' a

from USER_A.test_tab

;

View created.

exit

 

sqlplus USER_A/q1w2e3r4

 

create or replace view USER_B.vw_a2

as

select '1' a

from USER_A.test_tab

;

 

ORA-01031: insufficient privileges

 

 

exit


sqlplus / as sysdba


 

grant create any view to USER_A;

 

 

create or replace view USER_B.vw_a2

as

select '1' a

from USER_A.test_tab

;

View created.




 

drop user USER_A cascade;

drop user USER_B cascade;

 



===  3. 뷰 권한 확인  ====



select * from dba_sys_privs where grantee like 'USER%';



반응형
Posted by 돌고래트레이너
생계/Oracle2020. 6. 9. 20:48


테이블에 대한 권한을 role 에 주는 것과 바로 유저에게 주는 것에 차이가 있을까?



ex)  grant select on tabA to roleA  VS  grant select on tabA to userA


두 경우 모두 테이블을 직접 사용하는 것에는 차이가 없다. 


하지만 만약 role 로 부여받은 권한으로 pl/sql 을 작성하려고 하면 에러가 날 것이다. 





==============  테스트 스크립트 =================


-- 1. 테이블 오너 tab_user,  프로시져를 생성할  ddl_user  생성


create user tab_user identified by "q1w2e3r4";

conn tab_user/"q1w2e3r4" 

 

create user ddl_user identified by "q1w2e3r4"; 

conn ddl_user/"q1w2e3r4"

 

grant resource to tab_user;

grant connect to tab_user;

grant resource to ddl_user;

grant connect to ddl_user;

 

alter user tab_user quota 30M on users;

 

-- 2. 프로시저에 쓰일 테스트 테이블, 데이터 생성


create table tab_user.ddltest(

a int

;

 

insert into tab_user.ddltest values(1);

commit;


-- 3. 롤 생성

 

create role test_role;

grant select on tab_user.ddltest to test_role;

grant test_role to ddl_user;

 


sqlplus ddl_user/"q1w2e3r4"

 

select * from tab_user.ddltest;

=> 조회 가능 


-- 4. 테스트 프로시져 생성

 

create or replace procedure ddl_user.test_pcdr

is

 v_msg varchar2(100);

 begin

 

           select a into v_msg

           from tab_user.ddltest;

          

end;

/


=> PL/SQL: ORA-00942 : table or view does not exist


-- 5. 직접 권한 부여 


grant select on tab_user.ddltest to ddl_user;

 

이후에 프로시져를 생성하면 잘 된다. 




## 결론 : 권한관리를 위해 role 오브젝트를 사용하여 개발자에게 권한을 부여하지만

   pl/sql 을 사용하기 위해서는 직접 사용자에게 권한이 주어져야 한다. 


지금 조회되는 테이블이 role 을 부여받아서 조회가 되는건지 다이렉트로 권한을 받아서 되는건지

확인 하고자 할 때는 아래와 같이 하면 된다. 

 


select * from tab_user.ddltest;

 => 조회 가능 


set role none;

 

select * from tab_user.ddltest;

 => ORA-00942


이렇다면 role 로만 권한을 받은 것이다. 



 




반응형

'생계 > Oracle' 카테고리의 다른 글

오라클 라이선스 lifetime support  (0) 2021.08.26
create view , any view 권한  (0) 2020.06.16
DB를 사용한 채번 방식 알아보자  (0) 2020.04.30
오라클 로그인 특수문자 입력  (0) 2020.01.30
권한 확인 SQL  (0) 2019.08.29
Posted by 돌고래트레이너


얼머전에 미국 재난지원금 레터 도착에 대한 글을썼습니다.

그리고 어제 바로 실물을 받았네요.

지금보니까 처음 받았던 레터에서 바로 계좌로 쏴줄건지, 첵으로 보내줄건지 말해준거같습니다.

세금보고를 한 계좌가 아직 살아있으면 그리로 쏴주고 저처럼 다 정리한사람은 첵으로 보낸 모양입니다.


미국의 재난지원금은 1200불입니다.  역쉬 천조국..  

물론 일괄적으로 같은건 아니고 케이스마다 달라지는데 기본이 그정도 입니다.

한국에서는 15만원 받았는데, 기대도 안한 미국에서 훨씬 더 큰 금액을 받았습니다.


근데 나중에 알고보니 서울시 에서는 자영업자 개인사업자들에게 70 만원씩 두번을 지급한 모양입니다.

저도 개인사업자를 내긴했는데 지역이 경기도라 ㅠㅠ

근데 딱히 코로나로 수입이 줄거나 하진 않아서 아쉽진않구요. 정말 힘든 분들에게 돌아갔으면 하네요. 


무려 도널드 트럼프 미국대통령의 이름이 들어간 첵이다.

미국에서 돈만 쓰고 빈손으로 귀국했더니 이렇게 개평을

떼주는 아메리카!! 참 감사하다.

반응형
Posted by 돌고래트레이너