English 中文(简体)
我的无效性(ORA-00911)
原标题:Where s my invalid character (ORA-00911)

我试图在数据库中插入 CLOB (见 < a href= > 相关问题 ) 。 我无法完全找出错误。 我有一个大约85个立方体的清单要插入到表格中。 即使只插入第一个立方体我得到 < code> ORA- 0091: 无效字符 。 我无法在它执行前找到如何将语句从 < code> prepared Statement 调出, 所以我不能百分百确定它是正确的, 但如果我得到了正确的话, 那么它应该看起来完全这样:

insert all
  into domo_queries values ( select 
substr(to_char(max_data),1,4) as year,
substr(to_char(max_data),5,6) as month,
max_data
from dss_fin_user.acq_dashboard_src_load_success
where source =   CHQ PeopleSoft FS   )
select * from dual;

最终,这 < a href=> http://www.techonthenet.com/oracle/ questions/ Indeplication_rows.php> rel=“noreferr”\code> 插入所有 声明将有很多 into s。 这就是为什么我只是不做一个常规的 Indement 声明。我看不到里面有无效的字符,你呢? (Oh,当我用我的 sql 开发工具 < / strenger> 运行它时, < 坚固> 代码是好的) 。 如果我删除了 < code> prepared state 中的分号 <, 它会扔出一个 < code> ORA- 00933: SQL 命令没有正确结束 错误。

无论如何,这里是用于执行查询(以及上述变量的值)的代码。

public ResultSet executeQuery(String connection, String query, QueryParameter... params) throws DataException, SQLException {
  // query at this point = "insert all
                          //into domo_queries values (?)
                          //select * from dual;"
  Connection conn = ConnectionPool.getInstance().get(connection);
  PreparedStatement pstmt = conn.prepareStatement(query);
  for (int i = 1; i <= params.length; i++) {
    QueryParameter param = params[i - 1];
    switch (param.getType()) { //The type in the example is QueryParameter.CLOB
      case QueryParameter.CLOB:
        Clob clob = CLOB.createTemporary(conn, false, oracle.sql.CLOB.DURATION_SESSION);
        clob.setString(i, " " + param.getValue() + " ");
        //the value of param.getValue() at this point is:
        /*
         * select 
         * substr(to_char(max_data),1,4) as year,
         * substr(to_char(max_data),5,6) as month,
         * max_data
         * from dss_fin_user.acq_dashboard_src_load_success
         * where source =   CHQ PeopleSoft FS  
         */
        pstmt.setClob(i, clob);
        break;
      case QueryParameter.STRING:
        pstmt.setString(i, " " + param.getValue() + " ");
        break;
    }
  }
  ResultSet rs = pstmt.executeQuery(); //Obviously, this is where the error is thrown
  conn.commit();
  ConnectionPool.getInstance().release(conn);
  return rs;
}

有什么我错过了大日子吗?

最佳回答

如果您使用您向我们展示的字符串字典, 问题在于结尾处的 < code>; 字符。 在 JDBC 调用时, 您可能不会在查询字符串中包含此字符串 。

当您只插入一行时, 普通的 < code> INSERT 即便插入多行, 也应该很好。 使用分批的语句可能更有效率。 不需要 < code> INSERT ALL 。 此外, 您不需要临时的木块和所有的东西。 您可以简化方法, 类似这样的东西( 假设我拥有参数的权利 ) :

String query1 = "select substr(to_char(max_data),1,4) as year, " + 
  "substr(to_char(max_data),5,6) as month, max_data " +
  "from dss_fin_user.acq_dashboard_src_load_success " + 
  "where source =  CHQ PeopleSoft FS ";

String query2 = ".....";

String sql = "insert into domo_queries (clob_column) values (?)";
PreparedStatement pstmt = con.prepareStatement(sql);
StringReader reader = new StringReader(query1);
pstmt.setCharacterStream(1, reader, query1.length());
pstmt.addBatch();

reader = new StringReader(query2);
pstmt.setCharacterStream(1, reader, query2.length());
pstmt.addBatch();

pstmt.executeBatch();   
con.commit();
问题回答

在我的头顶上,你能尝试用 q 运算符来做字符串字典吗?

类似的东西

insert all
  into domo_queries values (q [select 
substr(to_char(max_data),1,4) as year,
substr(to_char(max_data),5,6) as month,
max_data
from dss_fin_user.acq_dashboard_src_load_success
where source =  CHQ PeopleSoft FS ] )
select * from dual;

请注意,你的上游的单引号没有逃脱, 弦在 q [...]之间。

原因之一可能是如果表格列中的任何一列在其名称中有一个 < 强'underscore (_) 。 JDBC 认为该字符无效 。 将列重新命名为 ALTER 命令, 并修改您将修补的 SQL 代码 。

Oracle对>ORA-00911提供一些解释。您在 Oracle SQL 开发商执行 SQL 请求后可以得到这一解释。

ORA-00911. 00000 - "invalid character" *Cause: identifiers may not start with any ASCII character other than letters and numbers. $#_ are also allowed after the first character. Identifiers enclosed by doublequotes may contain any character other than a doublequote. Alternative quotes (q #...# ) cannot use spaces, tabs, or carriage returns as delimiters. For all other contexts, consult the SQL Language Reference Manual

但对于你来说,这似乎是双重性格





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签