1.单个传入传出参数
create or replace procedure procedure_in_name_out_email(
i_name in o_user.username%type,
o_email out o_user.email%type) is
cursor getEmail(na varchar2) is
select email from o_user where o_user.username = na;
begin
open getEmail(i_name);
fetch getEmail
into o_email;
dbms_output.put_line(o_email);
close getEmail;
end procedure_in_name_out_email;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class CallableOracle {
public static void main(String[] args){
try{
Class.forName("oracle.jdbc.OracleDriver");
String url="jdbc:oracle:thin:@127.0.0.1:1521:king11g";
String name="programmer";String pass="password";
Connection conn=DriverManager.getConnection(url,name,pass);
Statement stmt=conn.createStatement();
CallableStatement proc = conn.prepareCall
("{ call procedure_in_name_out_email(?,?)}");
proc.setString(1, "username9");
proc.registerOutParameter(2, java.sql.Types.VARCHAR);
proc.execute();
String str=proc.getString(2);
System.out.println(str);
if(stmt!=null){stmt.close();}
if(conn!=null){conn.close();}
}catch(SQLException se){
se.printStackTrace();
}
catch(ClassNotFoundException ce){
ce.printStackTrace();
}
}
}
本文介绍了一个使用PL/SQL存储过程从Oracle数据库检索用户电子邮件的示例,并展示了如何通过Java程序调用该存储过程。此过程首先定义了一个PL/SQL存储过程,用于根据用户名获取对应的电子邮件地址,然后通过Java的CallableStatement实现对该存储过程的调用。
1014

被折叠的 条评论
为什么被折叠?



