我正在尝试在Oracle中创建一个表我正在使用以下SQL:
CREATE TABLE SALES_TARGET(
SLS_REP_SK NUMBER(38, 0) NOT NULL,
MARKET_PRODUCT_HRCHY_SK NUMBER(38, 0) NOT NULL,
FISCAL_PERIOD VARCHAR2(6) NOT NULL
CONSTRAINT VALID_FISCAL_PERIOD CHECK (LENGTH(FISCAL_PERIOD) = 6 AND REGEXP_LIKE(FISCAL_PERIOD, '^\d*$') AND (SUBSTR(FISCAL_PERIOD, 1, 4) BETWEEN '2010' AND '2050') AND (TO_NUMBER(SUBSTR(FISCAL_PERIOD, 5, 2)) BETWEEN 1 and 12)),
CURR_SK NUMBER(38, 0) NOT NULL,
SALES_TARGET_AMT NUMBER(18, 5) NOT NULL
CONSTRAINT POSITIVE_SALES_TARGET CHECK (SALES_TARGET_AMT >= 0),
ETL_BATCH_ID NUMBER(38, 0) NOT NULL,
ETL_CREATED_LOAD_DT DATE NOT NULL,
ETL_MODIFIED_LOAD_DT DATE NOT NULL,
CONSTRAINT PK_SALES_TARGET PRIMARY KEY (SLS_REP_SK, MARKET_PRODUCT_HRCHY_SK, FISCAL_PERIOD)
USING INDEX
TABLESPACE DWH_NRM_INDEX
)
TABLESPACE DWH_NRM_DATA
;
由于约束名称冲突而返回以下错误
Error report -
SQL Error: ORA-02264: name already used by an existing constraint
02264. 00000 - "name already used by an existing constraint"
*Cause: The specified constraint name has to be unique.
*Action: Specify a unique constraint name for the constraint.
正如其他问题建议使用查询,例如:
select * from ALL_constraints where constraint_name = 'PK_SALES_TARGET';
这没有返回任何结果(我已经尝试了上面的其他约束名称并且它们返回没问题)。
任何人都可以帮我找到我缺少的约束吗?
答案 0 :(得分:1)
你认识3个约束
CONSTRAINT VALID_FISCAL_PERIOD
CONSTRAINT POSITIVE_SALES_TARGET
CONSTRAINT PK_SALES_TARGET
请检查它们是否已存在?