我們在 Oracle 存儲過程中需要遍歷一張表,應該怎樣做。我想大多少的人第一個念頭就是 Cursor 。 比如: create or replace procedure StudyCursor( res" name="description" />

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • [PL/SQL] 用For Loop 替代Cursor

    發表于:2007-05-25來源:作者:點擊數: 標簽:sqlCursor宋體替代for
    MI LY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我們在 Oracle 存儲過程中需要遍歷一張表,應該怎樣做。我想大多少的人第一個念頭就是 Cursor 。 比如: create or replace procedure StudyCursor( res

    MILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我們在Oracle存儲過程中需要遍歷一張表,應該怎樣做。我想大多少的人第一個念頭就是Cursor。

     

     

    比如:

    create or replace procedure StudyCursor(
    resulst out integer
    ) is
    v_tablename varchar(
    30
    );
    v_tabletype varchar(
    11
    );
    cursor mycursor is select * from cat;
    begin
      open mycursor;
      loop
        fetch mycursor into v_tablename,v_tabletype;

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

     

     

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

    create or replace procedure StudyFor(
    resulst out integer
    ) is
    begin
      for emm in(select * from cat) loop
          null;  --you can use emm.table_name and emm.table_type
      end loop;
      return ;
    end StudyFor;

     

     

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

     

     

          查找了Oracle的官方文檔,似乎沒有看見for loop的此種用法。確實很奇妙,只是不知道oracle內部具體的實現方法。

     

     

    關于作者

    樊歡 java愛好者,您可以通過heydaymail@hotmail.com與我聯系。

              Email、MSN heydaymail@hotmail.com

           Blog http://heyday.blogone.net

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>