简体   繁体   English

将大型字符串数组作为VarChar2传递到SQL

[英]Delivering a large String Array as a VarChar2 into SQL

Our application makes heavy use of SQL functions. 我们的应用程序大量使用SQL函数。 One such function utilizes a large String variable of this sort: 一个这样的函数利用了这种大的String变量:

public static boolean callSQL(Connection conn, String[] s)
    throws DatabaseException
{
    boolean result = false;
    String query = "begin ? := "+qualProc("callSQL")+"(?); end;";
cs.registerOutParameter(1, Types.INTEGER);
**cs.setString(2, GeneralUtils.join(s,","));**
**cs.execute();**
        if(cs.getInt(1) > 0)
            result = true;
    }catch(SQLException se){
        se.printStackTrace(); 
        throw new DatabaseException(se.getMessage());
    }finally{
        if(cs != null)
            try{ cs.close(); }catch(SQLException e){}
    }

    return result;
}

Note: qualProc is the name of our database. 注意:qualProc是我们数据库的名称。 For security reasons I'm not using the real name here. 出于安全原因,我在这里不使用真实姓名。

The application itself runs smoothly, but when it attempts to execute the SQL command, we get the following error: 应用程序本身运行平稳,但是在尝试执行SQL命令时,出现以下错误:

ORA-06532: Subscript outside of limit ORA-06512: at "XXXX.XX", line XXX ORA-06512: at line X

In the package function itself, it uses the String like this: 在包函数本身中,它使用如下字符串:

  FUNCTION callSQL(s_tring IN VARCHAR2)
RETURN INTEGER IS

That string can (and has been) longer than the size limit for VarChar2 (32768 Bytes according to this answer https://stackoverflow.com/a/186436/2188082 ). 该字符串可以(并且已经)长于VarChar2的大小限制(根据此回答https://stackoverflow.com/a/186436/2188082的 32768字节)。

One option is to separate our Array into manageable chunks and run the SQL Function until it has processed the entire string, but ideally we would like to resolve this with a SQL package change - is there any way to make SQL accept a String that is too long for VarChar2? 一种选择是将Array分成可管理的块,然后运行SQL Function,直到处理完整个字符串为止,但是理想情况下,我们想通过更改SQL包来解决此问题-是否有任何方法可以使SQL接受也可以的String对VarChar2感兴趣吗?

I recommend you review the response to 5198856 , for sending array of String to PL / SQL. 我建议您查看对5198856的响应,以将String数组发送到PL / SQL。

On the other hand, you could modify the PL/SQL procedure that the parameter is a CLOB, not a VARCHAR2 whose limited to 32767 characters imposes a limitation that the CLOB type does not. 另一方面,您可以修改参数为CLOB的PL / SQL过程,而不是参数VARCHAR2(其限制为32767个字符)施加了CLOB类型没有的限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM