问题
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?
回答1:
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?
回答2:
For oracle if you include your sql between BEGIN and END; it should work.
Ex:
BEGIN
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;
END;
来源:https://stackoverflow.com/questions/4404141/how-to-include-multiple-commands-in-a-jdbc-sql-query-to-oracle-10g