【问题标题】:oracle missing keyword when creating tableoracle创建表时缺少关键字
【发布时间】:2017-10-23 19:51:39
【问题描述】:

我正在尝试在 oracle 中使用 sql 创建一个表。但是使用这个语句它给了我缺少关键字错误。但它在 w3school sql tryit 编辑器中运行良好。任何人都可以帮助我了解导致 oracle 问题的原因吗?

create table  products (product_key number(4) not null primary key, product_name varchar(50) not null unique, price_reg double(1000,2) not null, price_spec double(1000,2) not null, sell_reg double(1000,2) not null, sell_spec double(1000,2) not null)

所有帮助将不胜感激。

【问题讨论】:

  • 另一个很好的例子说明 w3fools 不是一个好的资源。

标签: sql oracle11g create-table


【解决方案1】:

您的问题是 Oracle 具有双精度数据类型和数字数据类型。你正在将两者结合起来。这里的“缺失关键字”是double 后面的“precision”一词。你要么想要这个:

create table  products (
product_key number(4) not null primary key, 
product_name varchar(50) not null unique, 
price_reg double precision not null, 
price_spec double precision not null, 
sell_reg double precision not null, 
sell_spec double precision not null)

或者这个:

create table  products (
product_key number(4) not null primary key, 
product_name varchar(50) not null unique, 
price_reg numeric(10,2) not null, 
price_spec numeric(10,2) not null, 
sell_reg numeric(10,2) not null, 
sell_spec numeric(10,2) not null)

SQL Fiddle demo

另请注意,1000 不是数字类型的有效精度值,最大值为 38(我在上面使用了 10)。

【讨论】:

    【解决方案2】:

    尽量不要使用 w3school 使用 oracle 文档
    已经给出答案了

    这里有一些有用的信息

    1. 表的单数名称
    2. 列的单数名称
    3. 表前缀的架构名称(例如:SchemeName.TableName)
    4. 帕斯卡套管(又名上驼峰套管)

    create table Product ( product_key number(4) not null primary key, product_name varchar(50) not null unique, price_reg double precision not null, price_spec double precision not null, sell_reg double precision not null, sell_spec double precision not null)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-17
      • 2020-02-08
      • 2012-09-26
      • 2016-11-09
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      • 2021-01-20
      相关资源
      最近更新 更多