Oracle SQL开发人员创建表时出错[已关闭]

xmd2e60i  于 2023-04-11  发布在  Oracle
关注(0)|答案(1)|浏览(181)

**已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。

这个问题是由一个错字或一个无法再复制的问题引起的。虽然类似的问题可能是on-topic在这里,但这个问题的解决方式不太可能帮助未来的读者。
4天前关闭。
Improve this question
从行开始时出错:1指挥-

CREATE TABLE CUSTOMER
(
    CustomerID   NUMBER(10)   GENERATED ALWAYS  AS IDENTITY   PRIMARY KEY,
    FirstName    VARCHAR2(50) NOT NULL,
    LastName     VARCHAR2(50) NOT NULL,
    BirthDate    DATE         NOT NULL,
    AddressLine1 VARCHAR2(50) NOT NULL,
    AddressLine2 VARCHAR2(50) NULL,
    City         VARCHAR2(30) NOT NULL,
    StateCode    CHAR(2)      UNIQUE NOT NULL,
    ZipCode      VARCHAR2(10) NOT NULL,
    Country      VARCHAR2(50) NOT NULL,
    Phone        VARCHAR2(20) NOT NULL,
    Email        VARCHAR2(50) UNIQUE NOT NULL,
    DriverLicenseNumber VARCHAR2(25) UNIQUE  NOT NULL,
    CustomerUserAccountID RAW(16)    NULL,
    CustomerType        CHAR(1)      
        CHECK(CustomerType in (R, C)) NOT NULL,
 
    CONSTRAINT fk_CUSTOMERUSERACCOUNT
        FOREIGN KEY (CustomerUserAccountID)
            REFERENCES CUSTOMERUSERACCOUNT(CustomerUserAccountID)
                ON DELETE CASCADE,
 
    CONSTRAINT fk_DRIVERLICENSE
        FOREIGN KEY (DriverLicenseNumber)
            REFERENCES  DRIVERLICENSE(DriverLicenseNumber)
                ON DELETE CASCADE
)

错误报告:
ORA-02438:列检查约束无法引用其他列02438。00000 -“列检查约束无法引用其他列”

  • 原因:试图定义引用另一列的列检查约束。
    *Action:定义为表检查约束。
    如何解决这个错误?
hs1ihplo

hs1ihplo1#

由于您没有将值括在单引号中,Oracle假定您正在尝试引用其他列。

No : CustomerType   CHAR(1)   CHECK(CustomerType in (R, C))     NOT NULL,

Yes: CustomerType   CHAR(1)   CHECK(CustomerType in ('R', 'C')) NOT NULL,

相关问题