jjklm

          用For Loop 替代Cursor

          ?轉(zhuǎn)載:http://doc.readmen.com/9/102220.shtml

          我們?cè)?/span>Oracle存儲(chǔ)過(guò)程中需要遍歷一張表,應(yīng)該怎樣做。我想大多少的人第一個(gè)念頭就是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;

          ?

          ?

          最近在看代碼是,發(fā)現(xiàn)其實(shí)我們還有一個(gè)更方便的方法就是使用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;

          ?

          ?

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

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


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 霍林郭勒市| 福鼎市| 贞丰县| 卓资县| 陕西省| 卫辉市| 武邑县| 五莲县| 凤冈县| 来安县| 连江县| 潮安县| 林周县| 乐业县| 林州市| 唐河县| 蓬安县| 桐柏县| 太仆寺旗| 广宗县| 佛坪县| 弥勒县| 金门县| 奇台县| 临桂县| 界首市| 桃园市| 冷水江市| 建瓯市| 营山县| 唐山市| 广安市| 融水| 广灵县| 天台县| 卢湾区| 沂水县| 巨野县| 巫山县| 新化县| 南召县|