如何在 Oracle 10g 的 JDBC SQL 查询中包含多个命令?
我对 Oracle 完全陌生(我来自 MySQL 和 MSSQL),并且是 JDBC 的新手。我的表创建查询之一如下所示:
CREATE TABLE "LISTS"
("ID" NUMBER NOT NULL ENABLE,
"NAME" VARCHAR2(1000) NOT NULL ENABLE,
"DOMAIN_ID" NUMBER NOT NULL ENABLE,
CONSTRAINT "LISTS_PK" PRIMARY KEY ("ID") ENABLE
)
/
CREATE OR REPLACE TRIGGER "BI_LISTS"
before insert on "LISTS"
for each row
begin
select "LISTS_SEQ".nextval into :NEW.ID from dual;
end;
/
ALTER TRIGGER "BI_LISTS" ENABLE
/
当我尝试 connection.createStatement().execute()
此查询时,我得到 java.sql.SQLSyntaxErrorException: ORA-00922: Missing or无效选项
。如果我删除斜杠,我会得到相同的结果。如果我尝试用分号替换它们,则会收到 java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
。
是否无法在 JDBC 和/或 Oracle 的一个查询中包含多个命令?或者我只是缺少某种语法来分隔它们?
I'm completely new to Oracle (I come from MySQL and MSSQL) and am novice at JDBC. One of my table creation queries looks like this:
CREATE TABLE "LISTS"
("ID" NUMBER NOT NULL ENABLE,
"NAME" VARCHAR2(1000) NOT NULL ENABLE,
"DOMAIN_ID" NUMBER NOT NULL ENABLE,
CONSTRAINT "LISTS_PK" PRIMARY KEY ("ID") ENABLE
)
/
CREATE OR REPLACE TRIGGER "BI_LISTS"
before insert on "LISTS"
for each row
begin
select "LISTS_SEQ".nextval into :NEW.ID from dual;
end;
/
ALTER TRIGGER "BI_LISTS" ENABLE
/
When I try to connection.createStatement().execute()
this query, I get java.sql.SQLSyntaxErrorException: ORA-00922: missing or invalid option
. If I remove the slashes, I get the same. If I try replacing them with semicolons, I get java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
.
Is it not possible to include multiple commands in one query in JDBC and/or Oracle? Or am I just missing some kind of syntax to separate them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 Oracle,如果您在 BEGIN 和 END 之间包含 sql;它应该有效。
前任:
For oracle if you include your sql between BEGIN and END; it should work.
Ex:
每一个都是单独的陈述。通过
Connection#createStatement()
或通过对Statement#execute(String)
的多个 SQL 调用,通过单独的 Statement 对象一次发出一个。相反,您希望将它们包含在一份明确的声明中的原因是什么?
Each of those are separate statements. Issue one at a time via separate Statement objects via
Connection#createStatement()
or via multiple SQL calls toStatement#execute(String)
.Conversely, what is your reason for wanting them in one delineated statement?