ORA-00933: SQL 命令未在 Groovy 脚本中正确结束
ORA-00933: SQL command not properly ended in Groovy Script
写了这个脚本:
static void schema()
{
Sql.newInstance(*DB_CONFIG, DB_DRIVER).execute('''
drop table if exists post;
drop table if exists author;
create table author(
id integer primary key,
name varchar(500)
);
create table post(
id integer primary key,
title varchar(500),
text longvarchar,
author integer not nul,
foreign key(author) references author(id)
);
''')
}
开始后,我看到了这个:
"WARNING: Failed to execute:
because: ORA-00933: SQL command not properly ended"
我正在使用 Oracle 11g 2 数据库和 oracle jdbc 驱动程序。
drop table if exists post;
drop table if exists author;
它不是有效的 Oracle 语法。您可以通过以下方式进行 -
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE post';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -942 THEN
RAISE;
END IF;
END;
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE author';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -942 THEN
RAISE;
END IF;
END;
还有一个语法错误-
author integer not nul,
更正为NOT NULL
。
写了这个脚本:
static void schema()
{
Sql.newInstance(*DB_CONFIG, DB_DRIVER).execute('''
drop table if exists post;
drop table if exists author;
create table author(
id integer primary key,
name varchar(500)
);
create table post(
id integer primary key,
title varchar(500),
text longvarchar,
author integer not nul,
foreign key(author) references author(id)
);
''')
}
开始后,我看到了这个:
"WARNING: Failed to execute: because: ORA-00933: SQL command not properly ended"
我正在使用 Oracle 11g 2 数据库和 oracle jdbc 驱动程序。
drop table if exists post; drop table if exists author;
它不是有效的 Oracle 语法。您可以通过以下方式进行 -
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE post';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -942 THEN
RAISE;
END IF;
END;
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE author';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -942 THEN
RAISE;
END IF;
END;
还有一个语法错误-
author integer not nul,
更正为NOT NULL
。