如何在对Oracle 10g的JDBC SQL查询中包含多个命令? [英] How to include multiple commands in a JDBC SQL query to Oracle 10g?
问题描述
我对Oracle完全陌生(我来自MySQL和MSSQL),并且是JDBC的新手.我的一个表创建查询如下:
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
/
当我尝试connection.createStatement().execute()
此查询时,得到java.sql.SQLSyntaxErrorException: ORA-00922: missing or invalid option
.如果删除斜杠,我将得到相同的结果.如果我尝试用分号替换它们,则会得到java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
.
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
.
在JDBC和/或Oracle中,是否不可能在一个查询中包含多个命令?还是我只是缺少某种语法来分隔它们?
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?
推荐答案
每个都是单独的语句.通过Connection#createStatement()
通过单独的Statement对象或通过对Statement#execute(String)
的多个SQL调用一次发出一个.
Each of those are separate statements. Issue one at a time via separate Statement objects via Connection#createStatement()
or via multiple SQL calls to Statement#execute(String)
.
相反,您为什么要在一份划定的陈述中要求他们?
Conversely, what is your reason for wanting them in one delineated statement?
这篇关于如何在对Oracle 10g的JDBC SQL查询中包含多个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!