重復容易,改變很難
          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 分享愛的空間 閱讀(5058) 評論(0)  編輯  收藏

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


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

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

          常用鏈接

          留言簿(5)

          隨筆檔案

          文章檔案

          相冊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 东乌珠穆沁旗| 溆浦县| 大同市| 石景山区| 晋中市| 吉安县| 南华县| 凉山| 新巴尔虎右旗| 班玛县| 秦安县| 合肥市| 上杭县| 化州市| 大荔县| 犍为县| 铜鼓县| 象山县| 甘肃省| 双桥区| 永春县| 游戏| 岳阳县| 辛集市| 阿克苏市| 舞钢市| 玉门市| 赫章县| 土默特左旗| 贞丰县| 玉田县| 徐汇区| 蒙自县| 黎川县| 渝中区| 荔波县| 昭觉县| 乌鲁木齐县| 沁水县| 公主岭市| 湖州市|