Getting an exception ORA-00942: table or view does not exist - when inserting into an existing table

前端 未结 10 1339
[愿得一人]
[愿得一人] 2020-11-28 15:17

I am getting below exception, when trying to insert a batch of rows to an existing table

ORA-00942: table or view does not exist

<
相关标签:
10条回答
  • 2020-11-28 15:50

    Is your script providing the schema name, or do you rely on the user logged into the database to select the default schema?

    It might be that you do not name the schema and that you perform your batch with a system user instead of the schema user resulting in the wrong execution context for a script that would work fine if executed by the user that has the target schema set as default schema. Your best action would be to include the schema name in the insert statements:

    INSERT INTO myschema.mytable (mycolums) VALUES ('myvalue')
    

    update: Do you try to bind the table name as bound value in your prepared statement? That won't work.

    0 讨论(0)
  • 2020-11-28 15:51

    There was no problem with my database connection properties or with my table or view name. The solution to the problem was very strange. One of the columns that I was trying insert was of Clob type. As I had a lot of trouble handling clob data in oracle db before, gave a try by replacing the clob setter with a temporary string setter and the same code executed with out any problems and all the rows were correctly inserted!!!.

    ie. peparedstatement.setClob(columnIndex, clob)

    was replaced with

    peparedstatement.setString(columnIndex, "String")

    0 讨论(0)
  • 2020-11-28 15:53

    @unbeli is right. Not having appropriate grants on a table will result in this error. For what it's worth, I recently experienced this. I was experiencing the exact problem that you described, I could execute insert statements through sql developer but would fail when using hibernate. I finally realized that my code was doing more than the obvious insert. Inserting into other tables that did not have appropriate grants. Adjusting grant privileges solved this for me.

    Note: Don't have reputation to comment, otherwise this may have been a comment.

    0 讨论(0)
  • 2020-11-28 15:56

    We experienced this issue on a BLOB column. Just in case anyone else lands on this question when encountering this error, here is how we resolved the issue:

    We started out with this:

                preparedStatement.setBlob(parameterIndex, resultSet.getBlob(columnName)); break;
    

    We resolved the issue by changing that line to this:

            java.sql.Blob blob = resultSet.getBlob(columnName);
            if (blob != null) {
                java.io.InputStream blobData =  blob.getBinaryStream();
                preparedStatement.setBinaryStream(parameterIndex, blobData);
            } else {
                preparedStatement.setBinaryStream(parameterIndex, null);
            }
    
    0 讨论(0)
提交回复
热议问题