如何在 Oracle 10g 的 JDBC SQL 查询中包含多个命令?

发布于 2024-10-07 02:09:42 字数 825 浏览 6 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拔了角的鹿 2024-10-14 02:09:42

对于 Oracle,如果您在 BEGIN 和 END 之间包含 sql;它应该有效。

前任:

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;

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;
寄人书 2024-10-14 02:09:42

每一个都是单独的陈述。通过 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 to Statement#execute(String).

Conversely, what is your reason for wanting them in one delineated statement?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文