Oracle 大量建立刪除多使用者

來源:互聯網
上載者:User

今天我們公司需求要求給每個客戶建立一個Oracle使用者,大概需求是300個Oracle使用者吧。後面會更多,如果手工建立的話估計很麻煩。找了一些方法結合實際吧,終於有個可以用的。可能是太簡單了。現在感覺,主要是這個是很基礎的oracle使用者基礎知識不過關。

方法如下:

for那個地方可以隨便指定oracle使用者的個數,要給oracle使用者適當的許可權,要不登陸不進去。


[oracle@developserver ~]$sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 14 19:41:45 2011

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

//建立暫存資料表空間 

create temporary tablespace ss_temp  tempfile '/home/oracle/ss/user_temp.dbf' size 1000m  autoextend on  next 50m maxsize 20480m  extent management local; 

connect system/oracle;


//建立資料資料表空間 

SQL>create tablespace ss_users_datalogging datafile '/home/oracle/ss/ss_users_data.dbf' size 1000m autoextend on next 50m   extent management local; 

SQL>declare

usernum varchar2(10);

begin

for i in 1..300

loop

usernum:=to_char(i);

execute immediate 'create user ss_'||usernum||' identified by uid5a default tablespace ss_users_data temporary tablespace ss_temp';

execute immediate 'grant resource,connect,dba to ss_'||usernum;

end loop;

end;

/

查詢建立的使用者列表

SQL>select username from dba_users;

用建立的使用者登入測試

SQL>connect ss_1/uid5a

注意:

1、斜杠/,不要省略,/表示提交,按ctrl+c退出終端;

2、identified by 後面是密碼,這邊的使用者密碼是字母i,注意不要在它的後面加空格,會產生不必要的錯誤。

3、預設建立的資料表空間是users資料表空間。

總結:使用者建立的基本知識很重要,通過這次的問題對oracle的建立使用者和pl/sql有了更深入的認識。www.bkjia.com那麼反過來是大量刪除使用者,批次更新使用者權限的話,只要把相關的語句修改完就可以了。

4、如果不指定資料表空間名稱,預設的資料表空間是users資料表空間。

大量刪除oracle使用者指令碼
declare
   usernum varchar2(10);
begin
   for i in 1..300
   loop
  usernum:=to_char(i);
   execute immediate 'drop user ss_'||usernum||' cascade';  end loop;
  end;
    /

那批量撤權使用者權限的話( revoke   許可權...   from  使用者名稱;),只要把drop相關的語句修改完就可以了

總結:使用者建立的基本知識很重要,通過這次的問題對oracle的建立使用者有了更深入的認識。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.