1818IP-服务器技术教程,云服务器评测推荐,服务器系统排错处理,环境搭建,攻击防护等

当前位置:首页 - 数据库 - 正文

君子好学,自强不息!

Oracle存储过程的实际用法解剖

2022-11-23 | 数据库 | 1818ip | 628°c
A+ A-

以下的文章主要讲述的是Oracle存储过程的实际的用法,本文是以想关的实际应用代码的方式来引出Oracle存储过程的实际操作流程,以下就是相关内容的具体描述,望你浏览之后会有所收获。

createtablestuInfo 
( 
stuIDintprimarykey, 
stuNamevarchar2(20) 
) 
createorreplaceprocedureproc1 
is 
begin 
insertintostuInfovalues(1,'liheng'); 
end; 
createorreplaceprocedureproc2 
( 
v_IDint, 
v_Namevarchar2 
) 
is 
begin 
insertintostuInfovalues(v_ID,v_Name); 
commit; 

记得要提交

end; 
createorreplaceprocedureproc3 
( 
v_IDint, 
v_Nameoutvarchar2 
) 
is 
varNamestuInfo.Stuname%type; 
begin 
selectstuNameintovarNamefromstuInfowherestuID=v_ID; 
v_Name:=varName; 
end; 

返回全部记录

createorreplacepackagePKG_STUINFOis 
typestuInfoCursorTypeisrefcursor; 
proceduregetStuInfo(stuInfoCursoroutstuInfoCursorType); 
end; 
createorreplacepackagebodyPKG_STUINFOis 
proceduregetStuInfo(stuInfoCursoroutstuInfoCursorType) 
is 
var_cursorstuInfoCursorType; 
begin 
openvar_cursorforselect*fromstuInfo; 
stuInfoCursor:=var_cursor; 
end; 
end; 

根据编号返回记录

createorreplacepackagePKG_STUINFOis 
typestuInfoCursorTypeisrefcursor; 
proceduregetStuInfo(v_IDint,stuInfoCursoroutstuInfoCursorType); 
end; 
createorreplacepackagebodyPKG_STUINFOis 
proceduregetStuInfo(v_IDint,stuInfoCursoroutstuInfoCursorType) 
is 
var_cursorstuInfoCursorType; 
begin 
ifv_ID=0then 
openvar_cursorforselect*fromstuInfo; 
else 
openvar_cursorforselect*fromstuInfowherestuID=v_ID; 
endif; 
stuInfoCursor:=var_cursor; 
end; 
end; 

根据姓名返回记录

createorreplacepackagePKG_STUINFOis 
typestuInfoCursorTypeisrefcursor; 
proceduregetStuInfo(v_Namevarchar2,stuInfoCursoroutstuInfoCursorType); 
end; 
createorreplacepackagebodyPKG_STUINFOis 
proceduregetStuInfo(v_Namevarchar2,stuInfoCursoroutstuInfoCursorType) 
is 
var_cursorstuInfoCursorType; 
begin 
ifv_Name=''then 
openvar_cursorforselect*fromstuInfo; 
else 
openvar_cursorforselect*fromstuInfowherestuNamelike'%'||v_Name||'%'; 
endif; 
stuInfoCursor:=var_cursor; 
end; 
end; 

本文来源:1818IP

本文地址:https://www.1818ip.com/post/11245.html

免责声明:本文由用户上传,如有侵权请联系删除!

发表评论

必填

选填

选填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。