orsen成長錄

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            3 隨筆 :: 2 文章 :: 0 評論 :: 0 Trackbacks
          --通過使用隱式游標和記錄為mydept表添加內(nèi)容
          Declare  
          Type  dept_rec 
          Is Record
          (
               r_deptno  dept.deptno
          %Type,
               r_dname   dept.dname
          %Type,
               r_loc     dept.loc
          %Type
          );
          v_deptrec   dept_rec;
          Begin
               
          Select deptno,dname,loc Into v_deptrec From dept
               
          Where deptno=&dno;
               
          Insert Into mydept Values v_deptrec;
                dbms_output.put_line(
          '插值成功');
               Exception 
               
          When NO_DATA_FOUND Then
               dbms_output.put_line(
          '該部門不存在');
               
          When Others Then
               dbms_output.put_line(
          '發(fā)生異常,插值失敗');
          End ;


          --結合游標從DEPT表中查詢數(shù)據(jù),將相應的數(shù)據(jù)插入到MYDEPT表中
          Declare  
          Type  dept_rec 
          Is Record
          (
               r_deptno  dept.deptno
          %Type,
               r_dname   dept.dname
          %Type,
               r_loc     dept.loc
          %Type
          );
          Cursor dept_cursor Is
          Select * From dept Order By deptno Asc;
          v_deptrec   dept_rec;
          Begin

                
          --打開游標
                Open dept_cursor;
                
          --從游標中取值
                Fetch dept_cursor Into v_deptrec;
                
          While(dept_cursor%Found) Loop
                     
          Insert Into mydept Values v_deptrec;
                dbms_output.put_line(
          '插值成功');
                
          Fetch dept_cursor Into v_deptrec;          
                
          End Loop;
                
          Close dept_cursor;
               Exception 
          When Others Then
               dbms_output.put_line(
          '發(fā)生異常,插值失敗');
          End ;


          --使用面向游標的記錄
          --
          通過面向游標的記錄顯示部門信息
          Declare Cursor dept_cursor
          Is
          Select * From mydept Order By deptno Asc;
          --定義一個面向游標的記錄
          v_deptrec dept_cursor%Rowtype;
          Begin
               
          Open dept_cursor;
               Loop 
               
          Fetch  dept_cursor Into v_deptrec;      
                    
          Delete From mydept Where deptno=v_deptrec.deptno;
                    dbms_output.put_line(v_deptrec.deptno
          ||' 信息刪除成功');
               
          Exit When dept_cursor%Notfound ;
               
          End Loop;
               
          Close dept_cursor;
               Exception 
          When Others Then
               dbms_output.put_line(
          '發(fā)生異常,刪除失敗');
          End;
          posted on 2009-09-24 12:58 Orsen 閱讀(139) 評論(0)  編輯  收藏 所屬分類: Oracle

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 宿松县| 东莞市| 贺兰县| 滦平县| 弥渡县| 公主岭市| 山阳县| 庐江县| 汤原县| 玉环县| 抚州市| 深圳市| 新源县| 互助| 大名县| 榆树市| 七台河市| 磴口县| 临漳县| 拉萨市| 平昌县| 南汇区| 信宜市| 安福县| 丰宁| 巫山县| 饶河县| 沿河| 蓝山县| 遂昌县| 遵义市| 扎鲁特旗| 岗巴县| 新沂市| 临颍县| 芒康县| 喀喇| 石河子市| 鲜城| 绍兴县| 乐安县|