java – ORA-00922:在oracle中执行“set long 100000”语句时缺少或无效选项

我正在开发一个java示例,其中我一个接一个地执行查询以获取indexces的ddl.我的java代码是 – Statement stmt2 = con.createStatement();ResultSet rs2 =null; String query = set lo...

我正在开发一个java示例,其中我一个接一个地执行查询以获取indexces的ddl.我的java代码是 –

Statement stmt2 = con.createStatement();
ResultSet rs2 =null;                             
String query = "set long 100000";
rs2 =stmt2.execute(query);
query = "set longchucksize 100000";
rs2 = stmt2.executeQuery(query);
query = "SELECT DBMS_METADATA.GET_DDL('INDEX','SYS_IL0000091971C00001$$','CCEEXPERTS') FROM dual";
rs2 = stmt2.executeQuery(queryForScript);

当以下语句运行时抛出ORA-00922:缺少或无效的选项异常

String query = “set long 100000”;

rs2 =stmt2.execute(query);

我如何执行这些陈述?

解决方法:

设置long 10000是SQL * PLUS命令,而不是标准SQL,这就是您遇到错误的原因.

ResultSet rs = stmt.executeQuery("SELECT DBMS_METADATA.GET_DDL('TABLE','YOUR_OBJECTS','JAY') as ddl FROM dual");

              while(rs.next()){
                  System.out.println(rs.getString(1));
              }

产量

CREATE TABLE "JAY"."YOUR_OBJECTS" 
   (    "OWNER" VARCHAR2(128) NOT NULL ENABLE, 
    "OBJECT_NAME" VARCHAR2(128) NOT NULL ENABLE, 
    "SUBOBJECT_NAME" VARCHAR2(128), 
    "OBJECT_ID" NUMBER NOT NULL ENABLE, 
    "DATA_OBJECT_ID" NUMBER, 
    "OBJECT_TYPE" VARCHAR2(23), 
    "CREATED" DATE NOT NULL ENABLE, 
    "LAST_DDL_TIME" DATE NOT NULL ENABLE, 
    "TIMESTAMP" VARCHAR2(19), 
    "STATUS" VARCHAR2(7), 
    "TEMPORARY" VARCHAR2(1), 
    "GENERATED" VARCHAR2(1), 
    "SECONDARY" VARCHAR2(1), 
    "NAMESPACE" NUMBER NOT NULL ENABLE, 
    "EDITION_NAME" VARCHAR2(128), 
    "SHARING" VARCHAR2(13), 
    "EDITIONABLE" VARCHAR2(1), 
    "ORACLE_MAINTAINED" VARCHAR2(1)
   ) SEGMENT CREATION IMMEDIATE 
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 
 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "ORAPDB1_TBS1" 

我在SQL * PLUS上运行相同的语句时得到了部分DDL.

SQL> SELECT DBMS_METADATA.GET_DDL('INDEX','SYS_IL0000092981C00086$$','JAY') as ddl FROM dual;

DDL
--------------------------------------------------------------------------------

  CREATE UNIQUE INDEX "JAY"."SYS_IL0000092981C00086$$" ON "JAY"."SYS_EXPORT_SCH

在这里,我可以通过设置SET LONG获得整个DDL但是我在Java Application上得到了完整的输出.

输出(Eclipse中)

  CREATE UNIQUE INDEX "JAY"."SYS_IL0000092981C00086$$" ON "JAY"."SYS_EXPORT_SCHEMA_01" (
  PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "ORAPDB1_TBS1" 
  PARALLEL (DEGREE 0 INSTANCES 0) 

本文标题为:java – ORA-00922:在oracle中执行“set long 100000”语句时缺少或无效选项

基础教程推荐