调用oracle存储过程并得到返回值
我用autoit 执行oracle的储存过程,可以执行,但是得不到执行结果。哪位大神做过,还请赐教
存储过程如下:
create or replace procedure AAA
(inum in number,
onum out number)
as
begin
onum:=inum*2;
end;
执行语句:
declare
onum number;
begin
aaa(3,onum);
DBMS_Output.Put_Line('onum:' || onum);
end;
配置文件:
$server = "ORCL"
$Userid = "justice"
$Password = "ROOT123"
$sql = "declare onum number; begin aaa(3,onum); DBMS_Output.Put_Line('onum:' || onum); end;"
$OraOBJConn = ObjCreate("ADODB.Connection") ; Create a COM ADODB Object with the Beta version
$connection = "DRIVER={Microsoft ODBC for Oracle};SERVER=" & $server & ";User Id=" & $UserID & ";Password=" & $Password ; Database connection definition
With $OraOBJConn
.connectionString = ($connection)
.open
EndWith
$OraOBJRecSet = ObjCreate("ADODB.RecordSet") ; Create a Record Set to handles SQL Records
$OraOBJRecSet.open($sql,$OraOBJConn);
$result = ""
If $OraOBJRecSet.recordcount <> 0 Then
$OraOBJRecSet.MoveFirst
For $i = 0 To $OraOBJRecSet.Fields.Count - 1
$result &= " " & $OraOBJRecSet.Fields($i).name
Next
$result &= @CRLF
While Not $OraOBJRecSet.EOF
For $i = 0 To $OraOBJRecSet.Fields.Count - 1
$result &= " " & $OraOBJRecSet.Fields($i).value
Next
$result &= @CRLF
$OraOBJRecSet.MoveNext
WEnd
EndIf 如何解决?? 配置文件这么多";"
到底你是在注释还是引用请重新用代码模式写出来 AU3文件跟配置文件距离分开一点.眼睛都看花了. 本帖最后由 dunphy 于 2013-10-20 01:00 编辑
在Oracle存储过程中有相关返回值的存储过程简介
存储过程为:
CREATE OR REPLACE PROCEDURE TESTB(PARA1 IN VARCHAR2,PARA2 OUT VARCHAR2) AS
BEGIN
SELECT INTO PARA2 FROM TESTTB WHERE I_ID= PARA1;
END TESTB;
在java里调用时就用下面的代码package com.hyq.src;
public class TestProcedureTWO {
public TestProcedureTWO() {
}
public static void main(String[] args ){
String driver = "Oracle.jdbc.driver.OracleDriver";
String strUrl = "jdbc:Oracle:thin:@127.0.0.1:1521:hyq";
Statement stmt = null;
ResultSet rs = null;
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(strUrl, " hyq ", " hyq ");
CallableStatement proc = null;
proc = conn.prepareCall("{ call HYQ.TESTB(?,?) }");
proc.setString(1, "100");
proc.registerOutParameter(2, Types.VARCHAR);
proc.execute();
String testPrint = proc.getString(2);
System.out.println("=testPrint=is="+testPrint);
}
catch (SQLException ex2) {
ex2.printStackTrace();
}
catch (Exception ex2) {
ex2.printStackTrace();
}
finally{
try {
if(rs != null){
rs.close();
if(stmt!=null){
stmt.close();
}
if(conn!=null){
conn.close();
}
}
}
catch (SQLException ex1) {
}
}
}
}
}注意,这里的proc.getString(2)中的数值2并非任意的,而是和存储过程中的out列对应的,如果out是在第一个位置,那就是proc.getString(1),如果是第三个位置,就是proc.getString(3),当然也可以同时有多个返回值,那就是再多加几个out参数了。以上就是对用java调用Oracle存储过程中有返回值的存储过程(非列表)相关的内容的介绍,望你会有所收获。
页:
[1]