Oracle 數據庫中創建表只讀用戶,併爲其設置密碼永不過期、同義詞。
1.創建用戶
create user test
identified by "123456"
default tablespace db
temporary tablespace dbTEMP;
2.資源授權
grant connect,resource to test;
3.表授讀權限
select 'grant select on '|| table_name|| ' to test;' from user_tables order by table_name
4.密碼永不過期
單獨創建一個profile文件,爲某用戶使用。
創建名爲passwd_unlimit的profile文件,設置其profile下密碼限定爲永不過期。
create profile passwd_unlimit limit PASSWORD_LIFE_TIME unlimited;
把passwd_unlimit的初始化參數設置到test用戶下。如下:
alter user test profile passwd_unlimit;
設置完成後,通過dba_users查看一下test用戶的profile文件是否設置成功,如下:
select username,user_id,account_status,expiry_date, profile from dba_users where username ='test';
可以看到test用戶的profile文件設置爲了passwd_unlimit,而passwd_unlimit的profile文件設定爲密碼永不過期了。
最後,命名爲PASSWD_UNLIMIT的profile文件下所附屬的資源設置都有哪些,如下:
SELECT * FROM dba_profiles WHERE profile = 'PASSWD_UNLIMIT';
5.同義詞
select 'create synonym test.'|| table_name|| ' for db.'||table_name||';' from user_tables
order by table_name