資料庫建使用者指令碼install.sh

來源:互聯網
上載者:User

標籤:tab   恢複   根據   immediate   exec   lin   tables   資料   手工   


--建立oracle使用者和資料表空間, 僅首次安裝系統時需要執行.
--若之前已建立同名的資料表空間或使用者, 則對應指令碼會被忽略.
declare
---------------------------------------------------------------
-- 以下配置請根據實際部署情況手工修改
---------------------------------------------------------------
--使用者名稱
v_username varchar2(1000) := ‘test‘;
--密碼
v_password varchar2(1000) := ‘1‘;
--資料檔案目錄, 這個目錄在ORACLE伺服器, 需要和DBA確認.
v_datafile_path varchar2(1000) := ‘/home/oracle/app/oradata/orcl‘;

--存放資料泵備份檔案的目錄, 這個目錄在ORACLE伺服器, 需要和DBA確認. 對應linux系統的目錄需要手工建立?
--v_directory_path varchar2(1000) := ‘/home/oracle/product/admin/ora11g/dpdump‘;
---------------------------------------------------------------
-- 以下資訊請勿修改
---------------------------------------------------------------
v_count number;
v_dir_name varchar2(1000); --目錄名稱
v_ts_name varchar2(1000); --當前庫資料表空間
begin
v_username := LOWER(v_username);
v_dir_name := LOWER(‘fmdmp_‘ || v_username);
v_ts_name := LOWER(v_username);

????--建立資料備份與恢複目錄
????select count(1) into v_count from dba_directories a where a.directory_name = UPPER(v_dir_name);
????if v_count = 0 then
???? execute immediate ‘create directory ‘ || v_dir_name || ‘ as ‘‘‘ || v_directory_path || ‘/‘ || v_username || ‘‘‘‘;
????end if;

????--建立當前庫資料表空間
????select count(*) into v_count from dba_tablespaces a where a.tablespace_name = UPPER(v_ts_name);
????if (v_count = 0) then
????????execute immediate ‘create tablespace ‘
|| v_ts_name || ‘ logging datafile ‘‘‘ || v_datafile_path || ‘/‘ || v_ts_name || ‘.dbf‘‘ size 512M‘
|| ‘ autoextend on next 512M‘
|| ‘ extent management local‘
|| ‘ segment space management auto‘;
????end if;
????
????--建立當前庫使用者
????select count(*) into v_count from dba_users a where a.username = UPPER(v_username);
????if (v_count = 0) then
????????execute immediate ‘create user ‘ || v_username || ‘ identified by ‘ || v_password || ‘ default tablespace ‘ || v_ts_name || ‘ temporary tablespace TEMP‘;
????end if;
execute immediate ‘grant connect, resource, dba, unlimited tablespace, create any table, select any table, grant any object privilege, create any synonym, drop any synonym to ‘ || v_username;
execute immediate ‘grant execute on utl_file to ‘ || v_username;
--授權目錄給當前庫使用者
????execute immediate ‘grant read,write on directory ‘ || v_dir_name || ‘ to ‘ || v_username;
????
????--授權查詢dba_directories給目前使用者
????execute immediate ‘grant select on sys.DBA_DIRECTORIES to ‘ || v_username;
end;
/

資料庫建使用者指令碼install.sh

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.