jjklm

          用For Loop 替代Cursor

          ?轉載:http://doc.readmen.com/9/102220.shtml

          我們在Oracle存儲過程中需要遍歷一張表,應該怎樣做。我想大多少的人第一個念頭就是Cursor

          ?

          ?

          比如:

          createorreplaceprocedure StudyCursor(
          resulst outinteger
          ) is
          v_tablename varchar(
          30
          );
          v_tabletype varchar(
          11
          );
          cursor mycursor isselect * from cat;
          begin
          ? open mycursor;
          ? loop
          ??? fetch mycursor into v_tablename,v_tabletype;

          null; --you can use tablename and v_tabletype
          ? endloop;
          ? close mycursor;
          end StudyCursor;

          ?

          ?

          最近在看代碼是,發現其實我們還有一個更方便的方法就是使用for ?in ?loop … ?end loop

          createorreplaceprocedure StudyFor(
          resulst outinteger
          ) is
          begin
          ? for emm in(select * from cat) loop
          ????? null;? --you can use emm.table_name and emm.table_type
          ? endloop;
          ? return ;
          end StudyFor;

          ?

          ?

          是不是更方便,我要使用的查詢結果,只需使用emm.table_nameemm.table_type即可。

          posted on 2006-11-28 10:35 天涯孤客 閱讀(84) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 昌吉市| 汝南县| 濮阳市| 博白县| 新安县| 浦城县| 大埔区| 蒲城县| 天祝| 辉县市| 青岛市| 比如县| 昌黎县| 博客| 百色市| 全州县| 汕尾市| 马关县| 夹江县| 涟源市| 集贤县| 平顺县| 张掖市| 新源县| 广东省| 江西省| 景宁| 海丰县| 中超| 稻城县| 龙泉市| 昌宁县| 梅州市| 三都| 萝北县| 彭泽县| 广州市| 雅安市| 文山县| 贵定县| 易门县|