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

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

君子好学,自强不息!

Oracle存储过程的代码的介绍

2022-11-26 | 数据库 | admin | 555°c
A+ A-

以下的文章是通过介绍Oracle存储过程的相关实际应用代码,来剖析Oracle存储过程的实际应用,以下就是相关内容的详细介绍。以下是文章的具体介绍,望你浏览完以下的内容会有所收获。

Oracle存储过程的用法

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

在Oracle存储过程中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*fromstuInfo
wherestuID=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/11799.html

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

发表评论

必填

选填

选填

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