java隨記

          堅持就是勝利!

           

          oracle 嵌套游標以及java,oracle的時間處理

           

          create or replace procedure test is
           
                 ids VOD_CMS_OPERATION_REGION.id%type; //變量ids與VOD_CMS_OPERATION_REGION表的id字段的類型一致
                 cursor cur_region is    select id from VOD_CMS_OPERATION_REGION; //定義游標
                 phoneId VOD_CMS_OPERATION_REGION2PHONE.id%type;
                 cursor cur_phone is select id from   VOD_CMS_OPERATION_REGION2PHONE  //第二個游標
                         where VOD_CMS_OPERATION_REGION2PHONE.REGION_ID=ids ;
                  
          begin
                 open cur_region;  //打開游標
                 loop    //循環
                   fetch cur_region  into ids;    //逐行處理游標把值放入變量 ids
                   exit when cur_region%notfound; //沒找到游標退出循環
                  
                   open cur_phone;
                   
                   loop                           
                     fetch cur_phone into phoneId; 
                     exit when cur_phone%notfound;
                     update VOD_CMS_OPERATION_REGION2PHONE set creater=1 where VOD_CMS_OPERATION_REGION2PHONE.id=phoneId;
                   end loop;
                   close cur_phone;
                  
                 end loop;
                 close cur_region; 關閉游標
                 commit;
          end test;


          程序處理oracle時間

            Calendar ca = Calendar.getInstance(Locale.CHINA);
            ca.setTime(new Date());
            ca.set(Calendar.HOUR_OF_DAY, 0);
            ca.set(Calendar.MINUTE,0);
            ca.set(Calendar.SECOND, 0);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            StringBuffer buffer = new StringBuffer();
            buffer.append("select cmsAssetObject.regionIds from CmsAssetObject cmsAssetObject where cmsAssetObject.validdate >= " );
            buffer.append("to_date('"+sdf.format(ca.getTime())+ "','yyyy-MM-dd hh24:mi:ss') ");
            ca.set(Calendar.HOUR_OF_DAY, 23);
            ca.set(Calendar.MINUTE,59);
            ca.set(Calendar.SECOND,59);
            buffer.append(" and cmsAssetObject.expiredate <= ");
            buffer.append("to_date('"+sdf.format(ca.getTime())+ "','yyyy-MM-dd hh24:mi:ss') ");
            buffer.append(" and cmsAssetObject.isWeather = 1");

          posted on 2009-03-09 10:50 傻 瓜 閱讀(794) 評論(0)  編輯  收藏 所屬分類: 雜項

          導航

          統計

          常用鏈接

          留言簿(7)

          我參與的團隊

          隨筆分類

          隨筆檔案

          文章分類

          友情鏈接

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 尖扎县| 博野县| 秀山| 红河县| 南和县| 耒阳市| 华坪县| 尼勒克县| 辛集市| 乌鲁木齐县| 绍兴市| 苏尼特右旗| 大足县| 鄂州市| 枣强县| 贵定县| 浦县| 弋阳县| 循化| 海原县| 冷水江市| 西乌珠穆沁旗| 连山| 汪清县| 安康市| 安国市| 莱阳市| 仪陇县| 麻江县| 法库县| 临泉县| 阜阳市| 汉寿县| 英德市| 汝州市| 滨州市| 二连浩特市| 靖江市| 乡宁县| 高陵县| 垫江县|