• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Prayer

            在一般中尋求卓越
            posts - 1256, comments - 190, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            DB2常用SQL的寫法(二)

            Posted on 2010-03-18 22:32 Prayer 閱讀(889) 評論(0)  編輯 收藏 引用 所屬分類: DB2
            -- for循環(huán)語句的用法 
            begin atomic
             declare fullname char(40);
             for vl as
               select firstnme, midinit, lastname from employee
              do
              set fullname = lastname concat ','
                concat firstnme concat ' ' concat midinit;
              insert into tnames values (fullname);
             end for
            end
             
            -- leave的用法
            create procedure leave_loop(out counter integer)
             language sql
             begin
               declare v_counter integer;
               declare v_firstnme varchar(12);
               declare v_midinit char(1);
               declare v_lastname varchar(15);
               declare at_end smallint default 0;
               declare not_found condition for sqlstate '02000';
               declare c1 cursor for
              select firstnme, midinit, lastname
                from employee;
               declare continue handler for not_found
              set at_end = 1;
               set v_counter = 0;
               open c1;
               fetch_loop:
               loop
              fetch c1 into v_firstnme, v_midinit, v_lastname;
              if at_end <> 0 then leave fetch_loop;
              end if;
              set v_counter = v_counter + 1;
               end loop fetch_loop;
               set counter = v_counter;
               close c1;
             end
             
            -- if語句的用法
               create procedure update_salary_if
                 (in employee_number char(6), inout rating smallint)
                 language sql
                 begin
                   declare not_found condition for sqlstate '02000';
                   declare exit handler for not_found
                     set rating = -1;
                   if rating = 1
                     then update employee
                     set salary = salary * 1.10, bonus = 1000
                     where empno = employee_number;
                   elseif rating = 2
                     then update employee
                     set salary = salary * 1.05, bonus = 500
                     where empno = employee_number;
                   else update employee
                     set salary = salary * 1.03, bonus = 0
                     where empno = employee_number;
                   end if;
                 end
             
            -- loop的用法
               create procedure loop_until_space(out counter integer)
                 language sql
                 begin
                   declare v_counter integer default 0;
                   declare v_firstnme varchar(12);
                   declare v_midinit char(1);
                   declare v_lastname varchar(15);
                   declare c1 cursor for
                     select firstnme, midinit, lastname
                       from employee;
                   declare continue handler for not found
                     set counter = -1;
                   open c1;
                   fetch_loop:
                   loop
                     fetch c1 into v_firstnme, v_midinit, v_lastname;
                     if v_midinit = ' ' then
                       leave fetch_loop;
                     end if;
                     set v_counter = v_counter + 1;
                   end loop fetch_loop;
                   set counter = v_counter;
                   close c1;
                 end
             
            -- return的用法
               begin
               ...
                 goto fail
               ...
                 success: return 0
                 fail: return -200
               end
             
            -- set變量 的用法
            set new_var.salary = 10000, new_var.comm = new_var.salary;
            or:
            set (new_var.salary, new_var.comm) = (10000, new_var.salary);
            set (new_var.salary, new_var.comm)
              = (select avg(salary), avg(comm)
                from employee e
                where e.workdept = new_var.workdept);
             
            -- whenever的用法
               exec sql whenever sqlerror goto handlerr;
               exec sql whenever sqlwarning continue;
               exec sql whenever not found go to enddata;
             
            -- while的用法
               create procedure dept_median
                 (in deptnumber smallint, out mediansalary double)
                 language sql
                 begin
                   declare v_numrecords integer default 1;
                   declare v_counter integer default 0;
                   declare c1 cursor for
                     select cast(salary as double)
                       from staff
                       where dept = deptnumber
                       order by salary;
                   declare exit handler for not found
                     set mediansalary = 6666;
                   set mediansalary = 0;
                   select count(*) into v_numrecords
                     from staff
                     where dept = deptnumber;
                   open c1;
                   while v_counter < (v_numrecords / 2 + 1) do
                     fetch c1 into mediansalary;
                     set v_counter = v_counter + 1;
                   end while;
                   close c1;
                 end
             
            -- set schema的用法
            set schema rick
             
            -- DB2保留關鍵字
            add                deterministic  leave         restart
            after              disallow       left          restrict
            alias              disconnect     like          result
            all                distinct       linktype      result_set_locator
            allocate           do             local         return
            allow              double         locale        returns
            alter              drop           locator       revoke
            and                dsnhattr       locators      right
            any                dssize         lock          rollback
            application        dynamic        lockmax       routine
            as                 each           locksize      row
            associate          editproc       long          rows
            asutime            else           loop          rrn
            audit              elseif         maxvalue      run
            authorization      encoding       microsecond   savepoint
            aux                end            microseconds  schema
            auxiliary          end-exec       minute        scratchpad
            before             end-exec1      minutes       second
            begin              erase          minvalue      seconds
            between            escape         mode          secqty
            binary             except         modifies      security
            bufferpool         exception      month         select
            by                 excluding      months        sensitive
            cache              execute        new           set
            call               exists         new_table     signal
            called             exit           no            simple
            capture            external       nocache       some
            cardinality        fenced         nocycle       source
            cascaded           fetch          nodename      specific
            case               fieldproc      nodenumber    sql
            cast               file           nomaxvalue    sqlid
            ccsid              final          nominvalue    standard
            char               for            noorder       start
            character          foreign        not           static
            check              free           null          stay
            close              from           nulls         stogroup
            cluster            full           numparts      stores
            collection         function       obid          style
            collid             general        of            subpages
            column             generated      old           substring
            comment            get            old_table     synonym
            commit             global         on            sysfun
            concat             go             open          sysibm
            condition          goto           optimization  sysproc
            connect            grant          optimize      system
            connection         graphic        option        table
            constraint         group          or            tablespace
            contains           handler        order         then
            continue           having         out           to
            count              hold           outer         transaction
            count_big          hour           overriding    trigger
            create             hours          package       trim
            cross              identity       parameter     type
            current            if             part          undo
            current_date       immediate      partition     union
            current_lc_ctype   in             path          unique
            current_path       including      piecesize     until
            current_server     increment      plan          update
            current_time       index          position      usage
            current_timestamp  indicator      precision     user
            current_timezone   inherit        prepare       using
            current_user       inner          primary       validproc
            cursor             inout          priqty        values
            cycle              insensitive    privileges    variable
            data               insert         procedure     variant
            database           integrity      program       vcat
            day                into           psid          view
            days               is             queryno       volumes
            db2general         isobid         read          when
            db2genrl           isolation      reads         where
            db2sql             iterate        recovery      while
            dbinfo             jar            references    with
            declare            java           referencing   wlm
            default            join           release       write
            defaults           key            rename        year
            definition         label          repeat        years
            delete             language       reset
            descriptor         lc_ctype       resignal
             
            -- SQL99關鍵字
            absolute       describe        module      session
            action         destroy         names       session_user
            admin          destructor      national    sets
            aggregate      diagnostics     natural     size
            are            dictionary      nchar       smallint
            array          domain          nclob       space
            asc            equals          next        specifictype
            assertion      every           none        sqlexception
            at             exec            numeric     sqlstate
            bit            false           object      sqlwarning
            blob           first           off         state
            boolean        float           only        statement
            both           found           operation   structure
            breadth        grouping        ordinality  system_user
            cascade        host            output      temporary
            catalog        ignore          pad         terminate
            class          initialize      parameters  than
            clob           initially       partial     time
            collate        input           postfix     timestamp
            collation      int             prefix      timezone_hour
            completion     integer         preorder    timezone_minute
            constraints    intersect       preserve    trailing
            constructor    interval        prior       translation
            corresponding  large           public      treat
            cube           last            real        true
            current_role   lateral         recursive   under
            date           leading         ref         unknown
            deallocate     less            relative    unnest
            dec            level           role        value
            decimal        limit           rollup      varchar
            deferrable     localtime       scope       varying
            deferred       localtimestamp  scroll      whenever
            depth          map             search      without
            deref          match           section     work
            desc           modify          sequence    zone
             
            中文精品久久久久人妻不卡| 少妇高潮惨叫久久久久久 | 人妻无码精品久久亚瑟影视| 国产高清美女一级a毛片久久w| 天天爽天天爽天天片a久久网| 久久婷婷综合中文字幕| 777米奇久久最新地址| 无码8090精品久久一区| 久久久久国产精品麻豆AR影院 | 国产午夜福利精品久久| 久久精品国产亚洲网站| 久久精品国产精品亚洲下载| 国产午夜福利精品久久| 欧美麻豆久久久久久中文| 日产久久强奸免费的看| 国产精品99久久久久久宅男小说| 无码人妻精品一区二区三区久久久| 亚洲美日韩Av中文字幕无码久久久妻妇| 亚洲va中文字幕无码久久不卡| 亚洲精品国精品久久99热一| 丰满少妇高潮惨叫久久久| 久久婷婷国产剧情内射白浆 | 亚洲国产香蕉人人爽成AV片久久 | 77777亚洲午夜久久多人| 亚洲AV无码1区2区久久| 99麻豆久久久国产精品免费| 曰曰摸天天摸人人看久久久| 亚洲乱码中文字幕久久孕妇黑人| 久久人人爽爽爽人久久久| 香蕉99久久国产综合精品宅男自| 久久天天躁狠狠躁夜夜2020一| 色欲综合久久中文字幕网| 国产一区二区精品久久岳| 国产精品久久久久久久久软件| 久久亚洲AV成人无码电影| 国产精品VIDEOSSEX久久发布| 久久91精品国产91| 中文字幕一区二区三区久久网站| 一本色道久久88综合日韩精品| 99久久99这里只有免费费精品| 亚洲精品无码久久毛片|