You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Oracle LiveSQL建表报ORA-00922缺失或无效选项错误排查求助

错误排查
  • 保留关键字用作字段名:desc是Oracle内置关键字,不能直接作为字段名,annuncio表中该字段应改为你逻辑模型中定义的descrizione。
  • 不存在的数据类型:Oracle无原生boolean、time数据类型:
    • annuncio表的di_persona boolean需改为di_persona number(1),可额外加约束check(di_persona in (0,1))对应布尔逻辑的假/真
    • offerta表的ora time需改为ora date(Oracle的date类型自带时分秒)或timestamp类型
  • Check约束不支持子查询:Oracle的表级Check约束不能嵌套SELECT查询,offerta表中校验CFutente不等于广告发布者的逻辑需通过触发器实现,不能直接写在Check里
  • 转义字符问题:代码中&lt;&gt;是HTML转义后的不等号,实际SQL需写为<>或!=
  • 可选逻辑对齐:utente表的逻辑模型包含cognome字段,建表语句遗漏,可按需补充
  • 语句结束符:每条建表语句末尾需添加分号;作为结束标识
修正后可正常执行的建表代码
/* Base di dati
KEYWORD(codice, nome)
UTENTE(CF, nome, cognome, email)
ANNUNCIO(codice, categoria, nome, descrizione, data_pubblicazione, data_scadenza, prezzo, comune, di_persona, tipo, CFUtente)
OFFERTA(CFutente, data, ora, importo, note, codice_annuncio)
INCLUSIONE(codice_keyword, codice_annuncio)
*/

/*
KEYWORD(codice, nome)
*/
create table keyword
(
    codice char(4) primary key,
    nome varchar(20)
);

/*
UTENTE(CF, nome, cognome, email)
*/
create table utente
(
    CF char(16) primary key,
    nome varchar(20),
    cognome varchar(20), -- 补充遗漏字段
    email varchar(20)
);

/*
ANNUNCIO(codice, categoria, nome, descrizione, data_pubblicazione, 
data_scadenza, prezzo, comune, di_persona, tipo, CFUtente)
*/
create table annuncio
(
    codice char(10) primary key,
    categoria varchar(11),
    check(categoria in ('elettronica','immobili','veicoli','altro')),
    nome varchar(20),
    descrizione varchar(100), -- 替换关键字desc
    data_pubb date,
    data_scad date,
    prezzo float,
    comune varchar(20),
    di_persona number(1), -- 替换boolean类型
    check(di_persona in (0,1)),
    tipo varchar(8),
    check(tipo in ('vendita','acquisto')),
    CFutente char(16) references utente(CF),
    check((tipo = 'vendita' AND di_persona is null) or (tipo = 'acquisto' and prezzo is null and comune is null))
);

/*
OFFERTA(CFutente, data, ora, importo, note, codice_annuncio)
*/
create table offerta
(
    CFutente char(16) references utente(CF),
    data date,
    ora date, -- 替换time类型
    importo float,
    note varchar(100),
    codice_annuncio char(10) references annuncio(codice),
    primary key(CFutente,data,ora)
    -- 原带子查询的Check约束删除,改用触发器实现对应校验逻辑
);

/*
INCLUSIONE(codice_keyword, codice_annuncio)
*/
create table inclusione
(
    codice_keyword char(4) references keyword(codice),
    codice_annuncio char(10) references annuncio(codice),
    primary key(codice_keyword,codice_annuncio)
);

注:offerta表的CFutente不能等于广告发布者的校验逻辑,可通过行级Before Insert/Update触发器实现,此处为保证语法正常执行先移除该约束。

内容的提问来源于stack exchange,提问作者Vito Martiradonna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 14:06:03