以下的文章是通过介绍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;
相关文章
标签:Oracle