没有表空间的特权 'USERS'

no privileges on tablespace 'USERS'

我有很多 table 可以插入行,但我只有一个 table;

出现此错误
Error starting at line 1 in command:
INSERT INTO ERRORLOG (MESSAGE) VALUES ('test')
Error report:
SQL Error: ORA-01950: no privileges on tablespace 'USERS'
01950. 00000 -  "no privileges on tablespace '%s'"
*Cause:    User does not have privileges to allocate an extent in the
           specified tablespace.
*Action:   Grant the user the appropriate system privileges or grant the user
           space resource on the tablespace.

我不是 Oracle 专家,但我从错误消息中了解到; 'USERS' table空间已满,我的用户无权扩展 table 空间但其他 tables'(我可以插入)table 空间' 是一样的.. 这是 sql 用于插入 table table 和出现错误的 table;

没问题;

  CREATE TABLE "MYUSER"."HEADSHIP" 
   (    "ID" NUMBER NOT NULL ENABLE, 
    "DESCRIPTION" VARCHAR2(255 BYTE), 
    "ISDELETED" VARCHAR2(1 BYTE) DEFAULT 0 NOT NULL ENABLE, 
     CONSTRAINT "HEADSHIP_PK" PRIMARY KEY ("ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS"  ENABLE, 
     CONSTRAINT "HEADSHIP_UI" UNIQUE ("DESCRIPTION")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS"  ENABLE
   ) SEGMENT CREATION IMMEDIATE 
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" ;


  CREATE OR REPLACE TRIGGER "MYUSER"."HEADSHIP_TRG" BEFORE INSERT ON HEADSHIP 
FOR EACH ROW 
BEGIN
  <<COLUMN_SEQUENCES>>
  BEGIN
    IF :NEW.ID IS NULL THEN
      SELECT HEADSHIP_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;
    END IF;
  END COLUMN_SEQUENCES;
END;
/
ALTER TRIGGER "MYUSER"."HEADSHIP_TRG" ENABLE;

获取错误;

CREATE TABLE "MYUSER"."ERRORLOG" 
   (    "ID" NUMBER NOT NULL ENABLE, 
    "MESSAGE" VARCHAR2(2048 BYTE), 
    "STACKTRACE" VARCHAR2(2048 BYTE), 
    "XDATE" DATE, 
    "USERLDAPNAME" VARCHAR2(127 BYTE), 
    "QUERY" VARCHAR2(2048 BYTE), 
     CONSTRAINT "ERRORLOG_PK" PRIMARY KEY ("ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS"  ENABLE
   ) SEGMENT CREATION IMMEDIATE 
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" ;


  CREATE OR REPLACE TRIGGER "MYUSER"."ERRORLOG_TRG" BEFORE INSERT ON ERRORLOG 
FOR EACH ROW 
BEGIN
  <<COLUMN_SEQUENCES>>
  BEGIN
    IF :NEW.ID IS NULL THEN
      SELECT ERRORLOG_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;
    END IF;
  END COLUMN_SEQUENCES;
END;
/
ALTER TRIGGER "MYUSER"."ERRORLOG_TRG" ENABLE;

您的用户 MYUSER 没有任何权限将数据插入 USERS tablespace。您必须授予用户插入 USERS tablespace 的权限或配额。您可以通过几种不同的方式执行此操作:

  1. 您可以给用户,例如MYUSERUSERStablespace:

    无限配额
    ALTER USER MYUSER QUOTA UNLIMITED ON USERS;
    
  2. 您还可以定义允许用户在 tablespace:

    上分配的最大值 space
    ALTER USER MYUSER QUOTA 100M ON USERS;
    
  3. 您还可以授予用户 UNLIMITED TABLESPACE 系统权限,这意味着他对数据库中的任何 tablespace 具有无限配额:

    GRANT UNLIMITED TABLESPACE TO MYUSER;
    

要获得有关 Oracle 数据库用户资源管理的更多信息,请查看 Oracle Database Documentation

如果您的用户在创建 table 时分配了 RESOURCEUNLIMITED TABLESPACE 角色,则可以获得此效果;但此后已被撤销,table 现在正在尝试分配新范围。您的用户没有为 tablespace 明确设置配额;如果它有那么你会看到 "ORA-01536: space quota exceeded for tablespace 'USERS'" 而不是,即使随后通过将其设置为零来删除配额。

查看效果:

-- grant unlimited tablespace to user;

create table t42 (id number) tablespace users;

Table t42 created.

insert into t42
select level as id
from dual
connect by level < 1000;

1,999 rows inserted.

select extents from user_segments where segment_name = 'T42';

   EXTENTS
----------
         1 

-- revoke unlimited tablespace from user;

此时我还能插入数据:

insert into t42 values (2000);

1 rows inserted.

但是如果我插入足够多的行以要求分配第二个范围,它会失败并出现此错误:

insert into t42
select level + 2000 as id
from dual
connect by level < 2000;

Error report -
SQL Error: ORA-01950: no privileges on tablespace 'USERS'
01950. 00000 -  "no privileges on tablespace '%s'"
*Cause:    User does not have privileges to allocate an extent in the
           specified tablespace.
*Action:   Grant the user the appropriate system privileges or grant the user
           space resource on the tablespace.

大概您的 DBA 一直在做一些特权管理工作,可能会撤销 RESOURCE,因为它已被弃用。

如评论中所述,您的 DBA 需要在 tablespace 上授予您一些 space,具有特定大小或(以匹配您之前的大小)没有限制:

grant quota unlimited on users to myuser;