重復容易,改變很難
          java,,,不錯的玩具
          posts - 21,  comments - 42,  trackbacks - 0

          create or replace package ArrayTestPKG1 is
             type tt_type is table of varchar(32) INDEX BY BINARY_INTEGER;  --- 定義數組
             type table2 is table of tableA.columnA%type index by binary_integer;

             function toArray(Liststr in varchar, V1 out tt_type) return number;
            
            
             Procedure test;
          END ArrayTestPKG1;

          /
          show errors;
          create or replace package body ArrayTestPKG1 is

             

              function toArray(Liststr in varchar, V1 out tt_type) return number is
                  TmpStr varchar(32);
                  Str    varchar(4000);
                  j      number;
              begin
                  Str := Liststr;
                  j   := 0;
                  IF Instr(Liststr, ',', 1, 1) = 0 THEN
                    V1(j) := Liststr;
                    j := j + 1;
                  else
                    While Instr(str, ',', 1, 1) > 0 Loop
                      TmpStr := Substr(str, 1, Instr(str, ',', 1, 1) - 1);
                   
                      V1(j) := TmpStr;
                      str := SubStr(Str, Instr(str, ',', 1, 1) + 1, length(str));
                      j := j + 1;
                    end loop;
                    if not str is null then
                     --將最后一個保存
                      V1(j) := str;
                      j := j + 1;
                    end if;
                  end if;
                  return J;
              EXCEPTION
            WHEN OTHERS THEN
                dbms_output.put_line('sqlerrm:'||sqlerrm);
              end;
           
           
            --計算某一天所有上下文的消費數據
            Procedure test Is

                t1 tt_type;
                v_char varchar(150):='';
                v_cnt  number:=0;
            Begin
           dbms_output.put_line('start!!!');
           
           v_char:='aaaa,bbbb,cccc,dddd,eee,ffff';
           v_cnt := toArray(v_char,t1);
           dbms_output.put_line('v_char:'||v_char);
           dbms_output.put_line('v_cnt:'||v_cnt);
           dbms_output.put_line('t1:'||t1(3));
           dbms_output.put_line('end!!!');
            End;

          begin
            -- Initialization
            Null;
          end ArrayTestPKG1;
          /
          show errors;


          SQL> exec ArrayTestPKG1.test;
          start!!!
          v_char:aaaa,bbbb,cccc,dddd,eee,ffff
          v_cnt:6
          t1:dddd
          end!!!

          PL/SQL procedure successfully completed.



          posted on 2007-12-05 14:48 分享愛的空間 閱讀(5053) 評論(0)  編輯  收藏

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


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           

          <2007年12月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          常用鏈接

          留言簿(5)

          隨筆檔案

          文章檔案

          相冊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 稻城县| 永登县| 游戏| 石首市| 盐池县| 龙里县| 龙井市| 毕节市| 临江市| 珠海市| 华坪县| 井研县| 大竹县| 长宁县| 五指山市| 麟游县| 铜梁县| 禄丰县| 嘉禾县| 海宁市| 全椒县| 盐山县| 锦屏县| 四川省| 建德市| 宁强县| 徐州市| 通渭县| 华容县| 朝阳市| 吉首市| 白河县| 榆社县| 福泉市| 井陉县| 偏关县| 舒兰市| 光泽县| 冷水江市| 裕民县| 和政县|