以下的文章主要讲述的是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;
相关文章
标签:Oracle