Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
返回数据的Oracle Java存储过程_Java_Oracle_Stored Procedures_Java Stored Procedures - Fatal编程技术网

返回数据的Oracle Java存储过程

返回数据的Oracle Java存储过程,java,oracle,stored-procedures,java-stored-procedures,Java,Oracle,Stored Procedures,Java Stored Procedures,我正在尝试编写一个Java存储过程,它可以返回一个结果。我在Oracle网站上找到了这个文档,但没有一个示例提供返回数据 我已经创建了以下包: CREATE OR REPLACE PACKAGE test_proc AS FUNCTION hello_world RETURN VARCHAR2; PROCEDURE insert_test(CHAINE VARCHAR2, NOMBRE NUMBER); END test_proc; 包体如下所示 CREATE OR REPLACE PAC

我正在尝试编写一个Java存储过程,它可以返回一个结果。我在Oracle网站上找到了这个文档,但没有一个示例提供返回数据

我已经创建了以下包:

CREATE OR REPLACE PACKAGE test_proc AS 
FUNCTION hello_world RETURN VARCHAR2;
PROCEDURE insert_test(CHAINE VARCHAR2, NOMBRE NUMBER);
END test_proc;
包体如下所示

CREATE OR REPLACE PACKAGE BODY test_proc AS
FUNCTION hello_world RETURN VARCHAR2 AS LANGUAGE JAVA
NAME 'TestProc.helloWorld() return java.lang.String';
PROCEDURE insert_test(CHAINE VARCHAR2, NOMBRE NUMBER) AS LANGUAGE JAVA
NAME 'TestProc.insertTEST(java.lang.String, int)';
END test_proc;
还有Java代码

public class TestProc {

public static void insertTEST(String chaine, int nombre) 
{
    System.out.println("Insert into test...");
    String sql = "INSERT INTO TEST VALUES(?,?)";
    try
    {
        Connection conn = DriverManager.getConnection("jdbc:default:connection:");
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, chaine);
        pstmt.setInt(2, nombre);
        pstmt.executeUpdate();
    }
    catch (SQLException e)
    {
        System.err.println(e.getMessage());     
    }
}

public static String helloWorld() 
{
    return "Hello world!!";
 }
}
我使用SQLDeveloper调用我的过程,使用以下说明

CALL test_proc.insert_test('test',1); #work
CALL test_proc.hello_world(); #doesn't work
执行第二条指令时,我出现以下错误ORA-06576:不是有效的函数或过程名称

你知道怎么解决这个问题吗?或者您知道在哪里可以找到在Oracle数据库中返回数据的java存储过程的工作示例吗

最终使用以下命令获得结果:

select test_proc.hello_world() from dual;
结果:

TEST_PROC.HELLO_WORLD()                                                              
-------------------------------------------------------------------------------------
Hello World!!
1 rows selected

您知道如何从数据库(如多行)返回复杂的结果吗?

对于返回某些内容的PL/SQL函数,您不能像在过程中一样在PL/SQL中调用它。将其作为函数调用。试一试

var test VARCHAR2(30)
CALL test_proc.hello_world() INTO :test;
print test

TEST
------------------------------------------
Hello world!!

var output VARCHAR2(30)将test_proc.hello_world()调用为:output;打印输出并出现以下错误:ORA-01008:“未绑定所有变量”(很抱歉格式化,在注释中似乎不起作用…)