PLS-00201: 必须声明标识符 'DBMS_SODA_ADMIN.DESCRIBE_COLLECTION'

PLS-00201: identifier 'DBMS_SODA_ADMIN.DESCRIBE_COLLECTION' must be declared

我正在使用 SODA for Java 从 oracle 12c 数据库中存储和检索文档。 我正在关注这个 example.

我在执行代码后遇到异常。

oracle.soda.rdbms.impl.SODAUtilsOracleSQLException at oracle.soda.rdbms.impl.SODAUtils.makeExceptionWithSQLText(SODAUtils.java:112) at oracle.soda.rdbms.impl.SODAUtils.makeExceptionWithSQLText(SODAUtils.java:75) at oracle.soda.rdbms.impl.OracleDatabaseImpl.loadCollection(OracleDatabaseImpl.java:1338) at oracle.soda.rdbms.impl.OracleDatabaseImpl.openCollection(OracleDatabaseImpl.java:410) at oracle.soda.rdbms.impl.OracleDatabaseImpl.createCollection(OracleDatabaseImpl.java:348) at oracle.soda.rdbms.impl.OracleDatabaseImpl.createCollection(OracleDatabaseImpl.java:332) at oracle.soda.rdbms.impl.OracleDatabaseImpl.createCollection(OracleDatabaseImpl.java:321) at oracle.soda.rdbms.impl.OracleDatabaseImpl.access0(OracleDatabaseImpl.java:62) at oracle.soda.rdbms.impl.OracleDatabaseImpl$OracleDatabaseAdministrationImpl.createCollection(OracleDatabaseImpl.java:1798) at com.cisco.salesconnect.lms.TestSoda.main(TestSoda.java:26) Caused by: java.sql.SQLException: ORA-06550: line 2, column 3: PLS-00201: identifier 'DBMS_SODA_ADMIN.DESCRIBE_COLLECTION' must be declared ORA-06550: line 2, column 3: PL/SQL: Statement ignored at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531) at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:204) at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1041) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1329) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584) at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3685) at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4714) at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1376) at oracle.soda.rdbms.impl.OracleDatabaseImpl.loadCollection(OracleDatabaseImpl.java:1317) ... 7 more

Java代码

try(OracleConnection conn = (OracleConnection) DriverManager.getConnection(/*connection url*/)) {

        conn.setImplicitCachingEnabled(true);
        conn.setStatementCacheSize(50);

        OracleRDBMSClient cl = new OracleRDBMSClient();

        OracleDatabase db = cl.getDatabase(conn);

        db.admin().createCollection("MyFirstJSONCollection");

    } catch (SCExceptions | SQLException | OracleException e) {
        e.printStackTrace();
    }
}

此异常背后的原因是什么?

在您调用 db.admin().createCollection("MyFirstJSONCollection"); 时执行的代码中某处引用了数据库中不存在的名为 DBMS_SODA_ADMIN.DESCRIBE_COLLECTION 的对象。您应该检查模式 DBMS_SODA_ADMIN 是否存在,以及该模式中是否存在名为 DESCRIBE_COLLECTION 的对象。一种方法是执行查询,例如

SELECT *
  FROM DBA_USERS u
  WHERE u.USERNAME = 'DBMS_SODA_ADMIN'

SELECT *
  FROM DBA_OBJECTS o
  WHERE o.OWNER = 'DBMS_SODA_ADMIN' AND
        o.OBJECT_NAME = 'DESCRIBE_COLLECTION'

如果缺少任何一个,则表明 Soda 数据库组件的安装未执行或未成功完成。如果这些东西确实存在,则表明您的代码所连接的用户没有访问此对象所需的权限。

您是否将 SODA_APP 角色授予您在其下创建 collection 的用户?例如:

将 SODA_APP 授予 userNameHere;

如果您不这样做,就会发生您遇到的错误。