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)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 凭祥市| 松阳县| 灯塔市| 华安县| 东乡县| 清水县| 南华县| 肇州县| 灵川县| 祁连县| 平罗县| 克拉玛依市| 漳州市| 修水县| 陵川县| 清徐县| 马龙县| 汝城县| 青浦区| 留坝县| 蓬溪县| 海阳市| 屏边| 平昌县| 来安县| 扶风县| 安溪县| 盐池县| 抚顺市| 湖南省| 彝良县| 喀喇沁旗| 湖北省| 通河县| 枝江市| 慈利县| 南雄市| 美姑县| 双桥区| 丹寨县| 江北区|