【问题标题】:ORA-001722 Invalid Number when insert in Oracle SQLORA-001722 在 Oracle SQL 中插入时数字无效
【发布时间】:2013-12-12 23:49:09
【问题描述】:
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 中有上述数据库,但是当我尝试运行插入命令时,我得到一个 ORA-1722 错误,Invalid Number。 user_status 表中有一个条目,对应于插入中的 1。

我已经坚持了好几天了。

【问题讨论】:

  • 数字不能用单引号括起来:'8679046' 是字符串值,8679046 是数字。 '001' 也不是数字。

标签: sql oracle


【解决方案1】:

引号不是问题 - 只要它们有效,它将隐式转换为数字。

检查你的约束:

CONSTRAINT check_Password CHECK (Password > 4)

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

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

也许你想这样做?

CONSTRAINT check_Password CHECK (length(Password) > 4)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-26
    • 1970-01-01
    • 2017-06-09
    • 2017-06-10
    • 1970-01-01
    相关资源
    最近更新 更多