简体   繁体   English

oracle 12g无效数字错误

[英]oracle 12g invalid number error

create table WeeklySaleReport
( ReportID varchar(20) primary key
, StartDate date
, EndDate date
, SaleAmount number (8,2)
, ComRate number (8,2)
, ComAmount number (8,2)
, EmployeeID int
, EName varchar(70)
, BrandID varchar(20)
, BName varchar(70)
, BSaleAmount number(8,2)
, TypeID varchar(20)
, TName varchar(20)
, TSaleAmount number(8,2)
, ESaleAmount number(8,2)
, EBonus number(8,2)
, DepartmentID references Department(DepartmentID) );

This table is made successfully 该表制作成功

but when trying to insert these fields, it gives me error "Invalid Number": 但是当尝试插入这些字段时,它给我错误“无效编号”:

insert into WeeklySaleReport
values
  ( 'R1', TO_DATE ('2018/06/16','yyyy/mm/dd')
  , TO_DATE ('2018/07/11','yyyy/mm/dd')
  , '9020.00', '2324.21', '20.00', 'E1'
  , 'Bassi', 'B1', 'Brand One', '123.00'
  , 'Type1', 'T One', '500.00', '123.00'
  , '555.00', 'D1' );

您已经在表中定义了EmployeeID int ,然后尝试将值'E1'插入该列。

I would strongly advise that you write your inserts more like this: 我强烈建议您将插入内容写成这样:

insert into WeeklySaleReport (ReportID, StartDate, EndDate, SaleAmount, ComRate, ComAmount,
                              EmployeeID, EName, BrandID, BName, BSaleAmount,
                              TypeID, TName, TSaleAmount, ESaleAmount, EBonus)
     values 'R1',                   -- ReportID
             DATE '2018-06-16',     -- StartDate
             DATE '2018-07-11',     -- EndDate
             9020.00,               -- SaleAmount
             2324.21,               -- ComRate
             20.00,                 -- ComAmount
             'E1'                   -- EmployeeId
    ---------^ ERROR
             'Bassi',               -- EName
             'B1',                  -- BrandId
             'Brand One',           -- BName
             123.00,                -- BSaleAmount
             'Type1',               -- TypeId
             'T One',               -- TName
             500.00,                -- TSaleAmount
             123.00,                -- ESaleAmount
             555.00,                -- Bonus
             'D1'                   -- DepartmentId
            );

Notes: 笔记:

  • List the columns in the update. 列出更新中的列。 Here, I've also added them as comments so you and others can follow what is going where. 在这里,我还添加了它们作为注释,以便您和其他人可以跟踪发生的情况。
  • EmployeeId is obviously an error. EmployeeId显然是一个错误。
  • Oracle recommends using VARCHAR2() rather than VARCHAR() for strings. Oracle建议对字符串使用VARCHAR2()而不是VARCHAR()
  • Know your types! 知道你的类型! Don't put single quotes around numeric constants. 不要在数字常量周围加上单引号。 It is misleading. 这是误导。
  • Use the DATE keyword. 使用DATE关键字。 It is ANSI standard and easier to read. 它是ANSI标准,更易于阅读。

And I just learned something. 我刚刚学到了一些东西。 The DepartmentId declaration is valid in Oracle, even though it does not have a type. 即使DepartmentId声明没有类型,它在Oracle中也是有效的。 Here is a SQL Fiddle. 是一个SQL Fiddle。 Most databases require the type definition in the table. 大多数数据库在表中都需要类型定义。 However, I still don't know if the value is valid, because the type is not clear in the question. 但是,我仍然不知道该值是否有效,因为问题中类型不清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM