oracle存储过程的使用
oracle存储过程使用简单例子
oracle中写好存储过程
1 create or replace procedure proc_delete(strid in 表名.字段%type,delresult out varchar2) 2 as 3 begin 4 delete from 表名 where 字段 = strid; 5 delresult := SQL%rowcount; 6 7 commit; 8 end proc_delete;
oracle中plsql调用
1 declare 2 rstr varchar2(20); 3 begin 4 proc_delete(参数,rstr); 5 dbms_output.put_line('results:'||rstr); 6 end;
java调用,需要导入oracle的驱动包
1 public class Testjdbc { 2 3 public void procDelete(int id){ 4 try { 5 6 Class.forName("oracle.jdbc.driver.OracleDriver"); 7 8 Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","test1_user","user123"); 9 10 CallableStatement callpstmt = conn.prepareCall("{call proc_delete(?,?)}"); 11 12 callpstmt.setInt(1, id); 13 14 callpstmt.registerOutParameter(2, Types.VARCHAR); 15 16 callpstmt.execute(); 17 18 String result = callpstmt.getString(2); 19 20 System.out.println(result); 21 22 callpstmt.close(); 23 24 conn.close(); 25 } catch (Exception e) { 26 27 e.printStackTrace(); 28 } 29 } 30 31 public static void main(String[] args) { 32 new Testjdbc().procDelete(30); 33 } 34 35 36 }