将自定义类型传递给 Oracle 过程
Posted
技术标签:
【中文标题】将自定义类型传递给 Oracle 过程【英文标题】:Pass custom type to Oracle procedure 【发布时间】:2019-05-08 17:16:15 【问题描述】:我有使用#include <occi.h>
的C++代码:
std::vector< std::string > arr"qw", "er", "ty";
stmt = conn->createStatement(
"BEGIN Clear_labels(:p_list1); END;");
setVector(stmt,1,arr,"MYCUSTOMTYPE");
stmt->execute();
现在我想编写 PL/SQL 命令将相同的命令发送到 DB。
MYCUSTOMTYPE:
TYPE "MYCUSTOMTYPE" as table of varchar2(255)
我觉得应该是这样的:
DECLARE list MYCUSTOMTYPE := MYCUSTOMTYPE("qw", "er", "ty")
BEGIN Clear_labels(list); END;
/
但我得到错误:
Invalid SQL type: sqlKind = UNINITIALIZED
org.jkiss.dbeaver.model.sql.DBSQLException: SQL Error [17439] [99999]: Invalid SQL type: sqlKind = UNINITIALIZED
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:134)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeStatement(SQLQueryJob.java:467)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.lambda$0(SQLQueryJob.java:407)
at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:146)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeSingleQuery(SQLQueryJob.java:405)
at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.extractData(SQLQueryJob.java:849)
at org.jkiss.dbeaver.ui.editors.sql.SQLEditor$QueryResultsContainer.readData(SQLEditor.java:2727)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.lambda$0(ResultSetJobDataRead.java:98)
at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:146)
at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.run(ResultSetJobDataRead.java:96)
at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:102)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.sql.SQLException: Invalid SQL type: sqlKind = UNINITIALIZED
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:74)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:30)
at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:931)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1150)
at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1792)
at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1745)
at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:334)
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.execute(JDBCStatementImpl.java:338)
at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:131)
... 11 more
【问题讨论】:
告诉我们MYCUSTOMTYPE
和Clean_labels
的定义
MYCUSTOMTYPE 在哪里定义?以及“它不起作用”是什么意思
我更新了帖子。
Potentially related,但请显示导致该错误的实际代码。
我添加了更多信息
【参考方案1】:
我决定试试sqlplus
,结果成功了:
$ sqlplus tests/tests@cdb1
SQL*Plus: Release 11.2.0.4.0 Production on Thu May 9 02:22:50 2019
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
SQL> DECLARE
2 p_list1 MYCUSTOMTYPE := MYCUSTOMTYPE('qw', 'er', 'ty');
3 BEGIN
4 Clear_labels(p_list1);
5 END;
6 /
PL/SQL procedure successfully completed.
SQL>
我认为问题出在DBeaver
。
【讨论】:
以上是关于将自定义类型传递给 Oracle 过程的主要内容,如果未能解决你的问题,请参考以下文章
Postgres:将自定义类型从 Java 传递给 postgres 函数