ORA-00922:缺少或无效的选项,无法创建表



我试图在Oracle LiveSQL中创建一些表,我得到ORA-00922:缺失或无效选项,但我无法弄清楚为什么它不起作用;下面是代码(注释代表关系模型中的表)。我为最终的愚蠢错误道歉,我完全是SQL编程的初学者。

/* 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),
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),
desc varchar(100),
data_pubb date,
data_scad date,
prezzo float,
comune varchar(20),
di_persona boolean,
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 time,
importo float,
note varchar(100),
codice_annuncio char(10) references annuncio(codice),
primary key(CFutente,data,ora),
check(CFutente <> (SELECT CFutente FROM annuncio WHERE 
codice=codice_annuncio))
)
/*
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)
)
  1. 您需要用;
  2. 终止每个语句Oracle没有booleanSQL数据类型。您可以使用di_persona NUMBER(1) CHECK (di_persona IN (1, 0))代替。
  3. desc为保留字,不能用作标识符;如果它是"描述"的缩写;那么你可以用descr代替。
  4. 不能在CHECK约束中使用子查询
  5. Oracle没有time数据类型。您可以使用INTERVAL DAY(0) TO SECOND代替;或者,如果dataora应该是日期和时间的组合,那么只使用data列作为DATE的数据类型总是具有年,月,日,时,分,秒组件,因此不需要单独的时间列。

create table keyword(
codice char(4) primary key,
nome varchar(20)
);
create table utente(
CF char(16) primary key,
nome varchar(20),
email varchar(20)
);
create table annuncio(
codice char(10) primary key,
categoria varchar(11),
check(categoria in ('elettronica','immobili','veicoli','altro')),
nome varchar(20),
descr varchar(100),
data_pubb date,
data_scad date,
prezzo float,
comune varchar(20),
di_persona NUMBER(1) CHECK (di_persona IN (1, 0)),
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)
)
);
create table offerta(
CFutente char(16) references utente(CF),
data date,
ora INTERVAL DAY(0) TO SECOND,
importo float,
note varchar(100),
codice_annuncio char(10) references annuncio(codice),
primary key(CFutente,data,ora)
);

db<此处小提琴>

最新更新