以下的文章主要介绍的是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;
Oracle存储过程的中我们要根据编号返回记录
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;
相关文章
标签:Oracle