存储过程是在大型数据库系统中,一组为了完成特定功能的SQL 语句集,经编译后存储在数据库中,用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它。
案例1:create tablemytable(name varchar2(30),password varchar2(30));
create or replace procedure sp_prol is
begin
--执行部分
insert into mytable values('韩顺平','m1234');
end;
/
调用:exec(关键字) sp_prol;
案例2:create proceduresp_pro2 is
begin
delete from mytable wherename='韩顺平';
end;
/
exec sp_prol;
create procedureupdate_prol
过程---
案例1:
带参数--
create proceduresp_pro5(spName varchar2,newSal number) is
begin
update emp setsal=newSal1 where ename=spName;
end;
/
在java里面调用存储过程:
Connectionct=DriverManager.getConnection("jdbc:orcle:thin:@127.0.0.1:1521:scott");
--创建一个叫CallableStatement
CallableStatementcs=ct.propareCall("{Call sp_pro3(?,?)}");
cs.setString(1,"Smith");
cs.setInt(2,1000)
cs.execute;
cs.close;
ct.close;