blogjava's web log

          blogjava's web log
          ...

          oracle練習(xí)(異常)

          create ?? table ?first
          (
          ??no?
          varchar2 ( 10 ),
          ??name?
          varchar2 ( 10 )
          )
          alter ? table ??first?modify?(no? number ); -- 修改表
          alter ? table ?first? add (id? number ) -- 添加列
          create ? table ?first1?
          (
          ??no?
          number ,
          ??name?
          varchar ( 20 )
          );
          alter ? table ?first? add ? primary ? key (no); -- 添加主鍵
          select ? * ? from ?first
          select ? * ? from ?first
          delete ?first? where ?no = ' 11 '
          -- 建序列
          create ?sequence?firstsquence

          select ?firstsquence.nextvar? from ?dual;
          select ?firstsquence.currval? from ?dual;

          insert ? into ?first? values ( ' 001 ' , ' wujunjun ' );
          insert ? into ?first? values ( ' 002 ' , ' wujun ' );
          insert ? into ?first? values ( ' 003 ' , ' lover ' );
          insert ? into ?first? values ( ' 004 ' , ' blogjava ' );
          select ? * ? from ?first
          drop ? table ?first

          declare
          vname?first.name
          % type;
          begin
          ?
          select ?name? into ?vname? from ?first? where ?no < ' 003 ' ;
          ?dbms_output.put_line(
          ' 成功 ' );
          ?exception?
          ??
          when ?too_many_rows? then
          ???dbms_output.put_line(
          ' 查詢返回不止一行 ' );
          ???
          when ?others? then
          ????dbms_output.put_line(
          ' 發(fā)生了其他錯(cuò)誤 ' );
          ??
          end ;

          -- 自己定義異常?
          declare
          ?myexception?exception;
          ?pragma?exception_init(myexception,
          - 1 );
          ?
          begin
          ???
          insert ? into ?first? values ( ' 001 ' , ' 11 ' );
          ???exception
          ???
          when ?myexception? then
          ????Dbms_Output.put_line(
          ' 錯(cuò)誤 ' );
          ???
          when ?others? then
          ???dbms_output.put_line(
          ' 其他錯(cuò)誤 ' );
          ?
          end ?;
          ??
          -- 拋出???
          ? declare ?
          ?myexception?exception;
          ??xm?first.no
          % type: = ' 001 ' ;
          ??
          begin
          ??
          ??
          if ?(xm = ' 002 ' )? then
          ??raise?myexception;
          ??
          else
          ????
          insert ? into ?first? values ( ' 005 ' , ' 222 ' );
          ???
          end ? if ;
          ???
          ???exception?
          ???
          when ?myexception? then
          ???dbms_output.put_line(
          ' myexception?error! ' );
          ??
          when ?others? then
          ??raise_application_error(
          ' -20001 ' , ' error?message ' );
          ??
          end ;
          ??
          -- %found用法
          declare
          ?xm?first.no
          % type;
          begin ?
          ?
          -- delete?from?first?where?name='001';
          ? select ?name? into ?xm? from ?first? where ?no = ' 002 ' ;
          ?
          if ?(sql % found = true)? then
          ??dbms_output.put_line(
          ' found ' );
          ??
          else
          ?????
          insert ? into ?first? values ( ' 002 ' , 33 );
          ?????dbms_output.put_line(
          ' not?found ' );
          ?
          end ? if ;
          end ;

          -- 游標(biāo)輸出no?和name
          declare
          ?xm?first
          % rowtype;
          ?
          cursor ?cc? is ? select ? * ? from ?first;
          begin ?
          ??
          for ?aa? in ?cc
          ??loop
          ??
          -- ??if(aa.name='002')?then
          ???dbms_output.put_line(aa.no || aa.name);
          ??
          -- ?end?if;
          ?? end ?loop;
          end ;

          declare
          TYPE?ref_cursor?
          IS ?REF? CURSOR ;


          -- 建包
          create ? or ? replace ?package?PKG_HOTLINE? is
          ????
          ????type?HotlineCursorType?
          is ?REF? CURSOR ;
            
          function ?getHotline? return ?HotlineCursorType;
           
          end ;
          -- 包主體
          create ? or ? replace ?package?body?PKG_HOTLINE? is
          ???
          function ?getHotline? return ?HotlineCursorType? is
          ??????hotlineCursor?HotlineCursorType;
            
          begin
          ?????
          open ?hotlineCursor? for ? select ? * ? from ?hotline;
            ?
          return ?hotlineCursor;
            
          end ;
           
          end ;
           
          begin

          end ;

          create ? or ? replace ?package?pack11? is
          ?type?ref_cursor1?
          is ?ref? cursor ?;
          ?
          function ?getCursor? return ?ref_cursor1;
          end ;

          create ? or ? replace ?package?body?pack11? is
          ?
          ?
          function ?getCursor? return ?ref_cursor1? is
          ??cc?ref_cursor1;
          ?
          begin
          ??
          open ?cc? for ? select ? * ? from ?first;
          ??
          return ?cc;
          ?
          end ;
          end ;

          posted on 2006-04-28 08:48 record java and net 閱讀(374) 評(píng)論(0)  編輯  收藏 所屬分類: Database

          導(dǎo)航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動(dòng)態(tài)語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評(píng)論

          主站蜘蛛池模板: 卢龙县| 大洼县| 大英县| 安义县| 乐陵市| 大竹县| 山西省| 连山| 绥德县| 晋城| 秦安县| 财经| 五指山市| 合山市| 长兴县| 比如县| 湘潭市| 宁晋县| 康马县| 顺义区| 调兵山市| 墨玉县| 铁岭县| 高密市| 镇巴县| 凉山| 大庆市| 沂源县| 宜都市| 南漳县| 蕲春县| 孝感市| 弋阳县| 海林市| 昌黎县| 札达县| 磐安县| 胶州市| 家居| 茌平县| 曲阳县|