jdbcTemplate.execute(new CallableStatementCreator() {
@Override
public CallableStatement createCallableStatement(final Connection paramConnection)
throws SQLException {
final CallableStatement cs = paramConnection.prepareCall("{call INSERT_ACP_ASSIGN_FUNCTION(?,?,?)}");
cs.setString(1, resourceId);
cs.setInt(2,resourceType);
cs.setArray(3, new PostgreSQLArray(accessControlPolicyIds));
return cs;
}
}, new CallableStatementCallback() {
public Object doInCallableStatement(final CallableStatement cs) throws SQLException{
cs.execute();
return null;
}
});
公共类PostgreSQL Larray实现数组{
private final String[] stringArray;
private final String stringValue;
public PostgreSQLArray(String[] stringArray) {
this.stringArray = stringArray;
this.stringValue = stringArrayToPostgreSQLArrayString(stringArray);
}
public String toString() {
return stringValue;
}
/**
*
* @param inputtedArray source String array
* @return string representation of a given integer array
*/
public static String stringArrayToPostgreSQLArrayString(String[] inputtedArray) {
if ( inputtedArray == null ) {
return "NULL";
}
final int al = inputtedArray.length;
if ( al == 0 ) {
return "{}";
}
StringBuilder sb = new StringBuilder();
sb.append('{');
for (int i = 0; i < al; i++) {
if ( i > 0 ) sb.append(',');
sb.append(inputtedArray[i]);
}
sb.append('}');
return sb.toString();
}
public Object getArray() throws SQLException {
return stringArray == null ? null : Arrays.copyOf(stringArray, stringArray.length);
}
public Object getArray(Map<String, Class<?>> map) throws SQLException {
return getArray();
}
public Object getArray(long index, int count) throws SQLException {
return stringArray == null ? null : Arrays.copyOfRange(stringArray, (int)index, (int)index + count );
}
public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException {
return getArray(index, count);
}
public int getBaseType() throws SQLException {
return java.sql.Types.INTEGER;
}
public String getBaseTypeName() throws SQLException {
return "varchar";
}
public ResultSet getResultSet() throws SQLException {
throw new UnsupportedOperationException();
}
public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException();
}
public ResultSet getResultSet(long index, int count) throws SQLException {
throw new UnsupportedOperationException();
}
public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException();
}
public void free() throws SQLException {
}
}
CREATE OR REPLACE FUNCTION iot1_0."INSERT_ACP_ASSIGN_FUNCTION"(
"I_RESOURCE_ID" character varying,
"I_RESOURCE_TYPE" integer,
"I_ACP_RESOURCE_ID" character varying[])
RETURNS void AS
$BODY$ DECLARE
acp_resource_id character varying;
acp_id integer;
BEGIN
for acp_resource_id in select $3 LOOP
RAISE NOTICE 'acp_resource_id is %', acp_resource_id;
select ID into acp_id from iot1_0.ACP_DEFINE where RESOURCEID = acp_resource_id;
RAISE NOTICE 'acp_id is %', acp_id;
insert into iot1_0.ACP_ASSIGN(resource_type, acp_id, resource_id) values ($2 , acp_id, $1);
END LOOP;
END;$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION iot1_0."INSERT_ACP_ASSIGN_FUNCTION"(character varying, integer, character varying[])
OWNER TO enterprisedb;
Sql我在Postgres admin中执行的是
SELECT iot1_0."INSERT_ACP_ASSIGN_FUNCTION"(
character varying '112w',
1,
array['1','2','3']
);
请帮帮我,我对邮局很陌生。我挣扎了很多天。
是否尝试添加“IOT1_0”到函数调用?您是否从与pgadmin相同的用户运行它?您可能还希望运行列出java代码中可用过程的查询之一,以查看哪些方法应该是可见的。
因此,im在将数据库从Oracle迁移到PGSql项目中,现在im修复了一些查询.我有一个这样的错误: 并且我在这个字符串生成器上发现了来自控制台的nvl错误
我使用DBEaver在PostgreSQL中创建了一个存储过程。我正试图通过从DBeaver调用过程将数据插入到表中。但这给了我一个错误 SQL错误[42883]:错误:函数public.proc_insert_test(integer,unknown,unknown,unknown,unknown,unknown,timestamp with time zone,integer,integer,
这里是上面代码的错误-> 没有与给定的名称和参数类型匹配的函数。您可能需要添加显式类型转换。
我在PostgreSQL中有一个存储过程,如下所示: 我的数据库中有带精度值的类型。对于numeric,我只需要使用。这条路对吗?
代码中的以下语句给了我一个错误: 是Postgres中的用户定义聚合函数,定义为: 错误消息为:
但这段代码有一个错误: 错误:函数log(数值,双精度)不存在行1:select log(2.7,c) 提示:没有函数与给定的名称和参数类型匹配。您可能需要添加显式类型转换。 查询:select log(2.7,c)context:pl/pgsql function inline_code_block line 11 at SQL语句SQL state:42883