ORA-02290: 违反检查约束

ORA-02290: check constraint violated

每当我尝试将值插入 table 时,我总是收到消息 "ORA-02290: check constraint violated"。

这是 table 商店的代码:

    CREATE TABLE STORE
    (
    StoreID INT PRIMARY KEY,
    StoreName VARCHAR2(30) NOT NULL,
    City VARCHAR2(30) NOT NULL,
    Country VARCHAR2(30) NOT NULL CHECK (Country IN('Singapore','India','United States','Peru','Phillippines','People''s Republic of China','Canada')),
    Phone VARCHAR2(30) NOT NULL,
    Fax VARCHAR2(30),
    Email VARCHAR2(50) UNIQUE,
    Contact VARCHAR2(30) NOT NULL,
    UNIQUE (StoreName, City)
    );

这是我要完成的 INSERT 语句:

    INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)
    VALUES (1, 'Eastern Sales', 'Singapore', 'Singapore', '65-543-1233', '65-543-1239', 'Sales@EasternSales.com.sg', 'Jeremy');

    INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)
    VALUES (2, 'Eastern Treasures', 'Manila', 'Philippines', '63-2-654-2344', '63-2-654-2349', 'Sales@EasternTreasures.com.ph', 'Gracielle');

    INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)   
    VALUES (3, 'Jade Antiques', 'Singapore', 'Singapore', '65-543-3455', '95-543-3459', 'Sales@JadeAntiques.com.sg', 'Swee Lai');

    INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)    
    VALUES (4, 'Andes Treasures', 'Lima', 'Peru', '51-14-765-4566', '51-14-765-4569', 'Sales@AndesTreasures.com.pe', 'Juan Carlos');

    INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)    
    VALUES (5, 'Eastern Sales', 'Hong Kong', 'People''s Republic of China', '852-876-5677', '852-876-5679', 'Sales@EasternSales.com.hk', 'Sam');

    INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)
    VALUES (6, 'Eastern Treasures', 'New Delhi', 'India', '91-11-987-6788', '91-11-987-6789', 'Sales@EasternTreasures.com.in', 'Deepinder');

    INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)    
    VALUES (7, 'European Imports', 'New York City', 'United States', '800-432-8766', '800-432-8769', 'Sales@EuropeanImports.com.sg', 'Marcello');

它创建了第 4 个、第 6 个和第 7 个值,但没有创建其余值。出了什么问题?

您违反了 CHECK 约束,因为允许的值与您尝试插入的值不匹配:

CHECK (Country IN('Singapore','India','United States','Peru','Phillippines','People''s Republic of China','Canada'))

VALUES (2, 'Eastern Treasures', 'Manila', 'Philippines', '63-2-654-2344', '63-2-654-2349', 'Sales@EasternTreasures.com.ph', 'Gracielle')

约束中的

'Phillippines' 与插入语句中的 'Philippines' 不匹配。

将 CHECK 约束中的国家/地区名称更正为 'Philippines',它将正常工作:

CREATE TABLE STORE
    (
    StoreID INT PRIMARY KEY,
    StoreName VARCHAR2(30) NOT NULL,
    City VARCHAR2(30) NOT NULL,
    Country VARCHAR2(30) NOT NULL 
      CHECK (Country IN(
        'Singapore','India','United States','Peru','Philippines','People''s Republic of China','Canada')),
    Phone VARCHAR2(30) NOT NULL,
    Fax VARCHAR2(30),
    Email VARCHAR2(50) UNIQUE,
    Contact VARCHAR2(30) NOT NULL,
    UNIQUE (StoreName, City)
    );