ORA-06502:PL / SQL:数字或值错误ORA-06512:第1行

时间:2015-11-25 12:17:49

标签: java oracle oracle11g

我正在使用这个基本代码来调用Oracle函数。

SELECT a.SURNAME, b.COL_Y
FROM TABLE_A a
RIGHT OUTER JOIN TABLE_B b
ON a.COL_X = b.ID or a.COL_X IS NULL

Oracle功能:

public void basicTest() throws Exception
    {
        System.out.println("Basic Oracle Function call test");
        // initialize the driver and try to make a connection
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "admin", "qwerty");

        // prepareCall uses ANSI92 "call" syntax
        CallableStatement cstmt = conn.prepareCall("{? = call AGENT_STATISTICS_FUNCTION(?)}");

        // get those bind variables and parameters set up
        cstmt.registerOutParameter(1, Types.VARCHAR);
        cstmt.setString(2, "agent");

        // now we can do it, get it, close it, and print it
        cstmt.execute();
        String result = cstmt.getString(1);
        conn.close();
        System.out.println(result);
    }

我收到此错误:

CREATE OR REPLACE FUNCTION AGENT_STATISTICS_FUNCTION(NAMEIN IN VARCHAR2

)
RETURN CLOB
AS
.................

    LINE CLOB;
...............

BEGIN

   LINE := EMPTY_CLOB();
   DBMS_LOB.CREATETEMPORARY(LINE,TRUE);
..............

    RETURN LINE;
END AGENT_STATISTICS_FUNCTION;
/

我尝试添加conn.prepareCall(“begin dbms_output.enable(200000);?:= AGENT_STATISTICS_FUNCTION(?); end;”);但结果是一样的。你能提出一些解决方案吗?在SQL Developer中代码运行正常吗?

1 个答案:

答案 0 :(得分:1)

您需要注册正确的输出类型:

cstmt.registerOutParameter(1, Types.CLOB);