【问题标题】:ORA-22922 while passing blob to oracle procedure from kotlin appORA-22922 从 kotlin 应用程序将 blob 传递给 oracle 过程
【发布时间】:2021-01-18 05:26:15
【问题描述】:

创建 BLOB 并将其传递给过程的代码:

override fun saveImage(pdByteArray: ByteArray?, imageFormat: String): Long {
    val blob = dataSource.connection.createBlob()
    blob.setBytes(1, pdByteArray)

    val parameters = hashMapOf(
            "p_image_data" to blob,
            "p_image_format" to imageFormat
    )

    val out = saveImageFileCall.execute(parameters)
    return ((out["p_file_id"] ?: 0) as BigDecimal).toLong()
}

Oracle 程序:

  PROCEDURE save_image(p_file_id          OUT    VARCHAR2,
                       p_image_data       IN     BLOB,
                       p_image_format     IN     VARCHAR2)
  IS
  BEGIN
    INSERT INTO images (image_id, image_data, image_format)
    VALUES (images_seq.nextval, p_image_data, p_image_format)
    RETURNING image_id INTO p_file_id;
  END;

结果是 ORA-22922。将不胜感激。

【问题讨论】:

标签: java oracle kotlin stored-procedures


【解决方案1】:

这个post 很有帮助

不需要创建 BLOB,您可以将简单的字节数组传递给过程 - 但您必须将该数组与 OracleTypes.BINARY 绑定:

saveImageFileCall = SimpleJdbcCall(jdbcTemplate)
                    .withSchemaName(dataSource.connection.schema)
                    .withCatalogName("images_pkg")
                    .withProcedureName("save_image")
                    .declareParameters(
                            SqlParameter("p_image_data", OracleTypes.BINARY),
                            SqlParameter("p_image_format", OracleTypes.NVARCHAR)
                    )
...
  val parameters = hashMapOf(
                "p_image_data" to pdByteArray,
                "p_image_format" to imageFormat
        )

  val out = saveImageFileCall.execute(parameters)


【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-26
    • 2017-03-09
    • 2011-07-09
    • 2015-05-23
    • 2011-05-01
    • 2017-10-24
    • 2020-09-17
    相关资源
    最近更新 更多