2012-01-14 85 views
-1

我有一些問題連接到數據庫使用的用戶用戶創建我已經created.Firstly我創建的用戶是這樣的:錯誤我與我創建

create user util1 identified by user1; 

create user util2 identified by user2; 

create user util3 identified by user3; 

create user util4 identified by user4; 

create user util5 identified by user5; 

create user util6 identified by user6; 

create user util7 identified by user7; 

create user util8 identified by user8; 

grant dba to util1,util2,util3,util4,util5,util6,util7,util8; 

select lpad(' ', 2*level) || granted_role "User, his roles and privileges" 
    from (select null grantee, username granted_role from dba_users where username like upper('%UTIL%') 
     union 
      select grantee, granted_role from dba_role_privs 
     union 
      select grantee, privilege from dba_sys_privs) 
              start with grantee is null 
              connect by grantee = prior granted_role; 

這是工作fine.But當我嘗試創建一個表使用「util1」的權利。這是行不通的:

connect util1/user1 AS SYSDBA; 
create table pr1(
      cod_subansamblu number(4), 
      denumire varchar2(20) not null, 
      cantitate number(7,3), 
      UM varchar2(3), 
      pret_unitar number(9,2), 
      cod_ansamblu number(4), 
      cod_sectie number(4) not null, 
      constraint pr1_cod_subansamblu_pk primary key(cod_subansamblu), 
      constraint pr1_UM_chk check(UM in ('BUC','ML','MP','MC','SET')) 
      ); 

我真的不知道什麼錯誤。幫助將不勝感激。

我收到的錯誤消息是:

Last Execution Details 

Results   


Statistics  Plan     

ORA-00900: invalid SQL statement 
+1

你爲什麼連 「'作爲sysdba'」。這應該只用於維護工作。同時授予「普通」用戶的DBA也不是一個好主意。如果這是一個開發數據庫,​​只需授予這些用戶「連接」和「資源」。如果它是一個生產數據庫,則應該分別向這些用戶授予'connect'和'CREATE'特權。 – 2012-01-14 14:26:12

+0

@a_horse_with_no_name - 甲骨文棄用在11g中RESOURCE(和CONNECT和DBA)。 http://docs.oracle.com/cd/B28359_01/network.111「Oracle建議您設計自己的數據庫安全角色,而不是靠這個角色。這個角色可能不會自動通過Oracle數據庫的未來版本創建」 /b28531/authorization.htm – APC 2012-01-14 23:03:00

+0

@APC:是的,我知道。這就是爲什麼我說生產數據庫不應該使用角色。但對於開發數據庫來說,這非常方便。 – 2012-01-14 23:14:27

回答

2

沒有什麼不對的CREATE TABLE語句:

SQL> create table pr1(
      cod_subansamblu number(4), 
      denumire varchar2(20) not null, 
      cantitate number(7,3), 
      UM varchar2(3), 
      pret_unitar number(9,2), 
      cod_ansamblu number(4), 
      cod_sectie number(4) not null, 
      constraint pr1_cod_subansamblu_pk primary key(cod_subansamblu), 
      constraint pr1_UM_chk check(UM in ('BUC','ML','MP','MC','SET')) 
      ); 2 3 4 5 6 7 8 9 10 11 

Table created. 

SQL> 

因此很難理解爲什麼它拋出ORA-00900,當你運行它。你用什麼客戶來運行它?在SQL * Plus?像TOAD這樣的IDE?你能否提供完整的會話的cut'n'paste,所以我們可以清楚地看到這是怎麼回事?


其他的事情要記住,如果你連接使用as sysdba您是否指定連接字符串用戶登錄到數據庫,SYS,不管:

SQL> conn apc/password as sysdba 
Connected. 
SQL> sho user 
USER is "SYS" 
SQL> 

(這僅當您以帳號或其他適當特權用戶的身份登錄到操作系統時纔有效)。

所以,你可能會認爲你正在運行的create table語句爲UTIL1但你實際上將運行它作爲SYS,這是不是一個好主意。其實這是不好的做法。

+0

+1來解釋「as sysdba」的真實含義 – 2012-01-14 23:19:32