首页 文章

ORA-001722在Oracle SQL中插入时的编号无效

提问于
浏览
0
CREATE TABLE the_user( Name VARCHAR(40) not null,
    Address VARCHAR(255) not null,
    Delivery_address VARCHAR(255),
    Email VARCHAR(25) not null,
    Phone INTEGER not null,
    Status INTEGER not null,
    Password VARCHAR(25) not null, 
    DOB DATE not null,
    PRIMARY KEY (Email),
    FOREIGN KEY (Status) REFERENCES User_Status (Status_Id),
    CONSTRAINT check_Password CHECK (Password > 4)
);


INSERT  INTO  the_user VALUES  (
    'Pergrin Took',
    '12 Bag end, hobbiton, The Shire, Eriador',
    'The address, Dublin',
    'ptook@lotr.com',
    '8679046',
    '001',
    'treebeard',
    TO_DATE('2013/11/04 14:11:34', 'yyyy/mm/dd hh24:mi:ss')
);

我在Oracle中有上面的数据库但是当我尝试运行insert命令时,我得到一个ORA-1722错误,无效数字 . user_status表中有一个条目,对应于插入中的1 .

我已经坚持了几天 .

1 回答

  • 1

    引号不是问题 - 只要它们有效,它就会被隐式转换为数字 .

    检查你的约束:

    CONSTRAINT check_Password CHECK (Password > 4)
    

    在这里,您尝试比较字符串和数字 - >在此比较中,Oracle总是尝试将两者都作为数字 - >密码失败并且您看到错误 .

    尝试使用而不是密码,例如'55',你会看到插入行 .

    也许你想这样做?

    CONSTRAINT check_Password CHECK (length(Password) > 4)
    

相关问题