• <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++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            DB2常用SQL的寫法(三)

            Posted on 2010-03-18 22:35 Prayer 閱讀(503) 評論(0)  編輯 收藏 引用 所屬分類: DB2
            --create type (結構化的)用法
               create type dept as
                  (dept name     varchar(20),
                     max_emps int)
                     ref using int
                  mode db2sql
               create type emp as
                 (name      varchar(32),
                 serialnum int,
                 dept      ref(dept),
                 salary    decimal(10,2))
                 mode db2sql
             
               create type mgr under emp as
                 (bonus     decimal(10,2))
                 mode db2sql
             
               create type address_t as
                 (street     varchar(30),
                 number     char(15),
                 city       varchar(30),
                 state      varchar(10))
                 not final
                 mode db2sql
                   method samezip (addr address_t)
                   returns integer
                   language sql
                   deterministic
                   contains sql
                   no external action,
                   method distance (address_t)
                   returns float
                   language c
                   deterministic
                   parameter style sql
                   no sql
                   no external action
             
               create type germany_addr_t under address_t as
                 (family_name varchar(30))
                 not final
                 mode db2sql
             
               create type us_addr_t under address_t as
                 (zip varchar(10))
                 not final
                 mode db2sql
               create type project as
                 (proj_name  varchar(20),
                  proj_id    integer,
                  proj_mgr   mgr,
                  proj_lead  emp,
                  location   addr_t,
                  avail_date date)
                  mode db2sql
             
            -- create type mapping的用法
            create type mapping my_oracle_date
              from local type sysibm.date
              to server type oracle
              remote type date
             
            create type mapping my_oracle_dec
              from local type sysibm.decimal(10,2)
              to server oracle1
              remote type number([10..38],2)
             
            create type mapping my_oracle_char
              from local type sysibm.varchar()
              to server oracle1
              remote type char()
             
            create type mapping my_oracle_dec
              to local type sysibm.decimal(10,2)
              from server oracle2
              remote type number(10,2)
             
            -- create user mapping的用法
            create user mapping for rspalten
              server server390
              options
              (remote_authid 'system',
              remote_password 'manager')
             
            create user mapping for marcr
              server oracle1
              options
              (remote_password 'nzxczy')
             
            -- case的用法 
            case v_workdept
              when'a00'
                then update department
                set deptname = 'data access 1';
              when 'b01'
                then update department
                set deptname = 'data access 2';
              else update department
                set deptname = 'data access 3';
            end case
             
            case
              when v_workdept = 'a00'
                then update department
                set deptname = 'data access 1';
              when v_workdept = 'b01'
                then update department
                set deptname = 'data access 2';
              else update department
                set deptname = 'data access 3';
            end case
             
            -- create trigger的用法
            create trigger new_hired
              after insert on employee
              for each row
              update company_stats set nbemp = nbemp + 1
             
            create trigger former_emp
              after delete on employee
              for each row
              update company_stats set nbemp = nbemp - 1
             
            create trigger reorder
              after update of on_hand, max_stocked on parts
              referencing new as n
              for each row
              when (n.on_hand < 0.10 * n.max_stocked)
              begin atomic
              values(issue_ship_request(n.max_stocked - n.on_hand, n.partno));
              end
             
            create trigger raise_limit
              after update of salary on employee
              referencing new as n old as o
              for each row
              when (n.salary > 1.1 * o.salary)
                     signal sqlstate '75000' set message_text='salary increase>10%'
             
            create trigger stock_status
              no cascade before update of quote on currentquote
              referencing new as newquote old as oldquote
              for each row
              begin atomic
                 set newquote.status =
                   case
                      when newquote.quote >
                            (select max(quote) from quotehistory
                            where symbol = newquote.symbol
                            and year(quote_timestamp) = year(current date) )
                         then 'high'
                      when newquote.quote < (select min(quote) from quotehistory
                            where symbol = newquote.symbol
                            and year(quote_timestamp) = year(current date) )
                         then 'low'
                      when newquote.quote > oldquote.quote
                         then 'rising'
                      when newquote.quote < oldquote.quote
                         then 'dropping'
                      when newquote.quote = oldquote.quote
                         then 'steady'
                   end;
              end
             
            create trigger record_history
              after update of quote on currentquote
              referencing new as newquote
              for each row
              begin atomic
                insert into quotehistory
                  values (newquote.symbol, newquote.quote, current timestamp);
              end
            -- create tablespace 的用法
            create tablespace payroll
              managed by database
              using (device'/dev/rhdisk6' 10000,
                device '/dev/rhdisk7' 10000,
                device '/dev/rhdisk8' 10000)
              overhead 12.67
              transferrate 0.18
             
            create tablespace accounting
              managed by system
              using ('d:\acc_tbsp', 'e:\acc_tbsp', 'f:\acc_tbsp')
              extentsize 64
              prefetchsize 32
            create tablespace plans
              managed by database
              using (device '/dev/rhdisk0' 10000, device '/dev/rn1hd01' 40000)
              on dbpartitionnum (1)
              using (device '/dev/rhdisk0' 10000, device '/dev/rn3hd03' 40000)
              on dbpartitionnum (3)
              using (device '/dev/rhdisk0' 10000, device '/dev/rn5hd05' 40000)
              on dbpartitionnum (5)
             
            -- 帶case查詢條件語句
            select (case b.organtypecode
                     when 'D' then
                      b.parent
                     when 'S' then
                      b.parent
                     else
                      b.id
                   end),
                   b.name
              from A_ORGAN b
             where b.id = 999
            久久久精品国产Sm最大网站| 人妻精品久久久久中文字幕| 久久无码中文字幕东京热| 久久人人爽人人爽人人片av麻烦| 丁香色欲久久久久久综合网| 久久成人精品视频| 色欲久久久天天天综合网精品 | 久久综合香蕉国产蜜臀AV| 一本大道加勒比久久综合| 久久久精品国产免大香伊| 久久影院久久香蕉国产线看观看| 少妇精品久久久一区二区三区| 久久伊人五月天论坛| 久久精品国内一区二区三区| 综合久久一区二区三区 | 久久这里只有精品久久| 国产成人久久精品一区二区三区| 国产一区二区精品久久凹凸| 久久人人爽人人爽人人AV东京热 | 久久99热精品| 国产精品久久波多野结衣| 无码AV波多野结衣久久| 伊人久久大香线蕉av一区| 久久久久亚洲精品日久生情| 麻豆精品久久久久久久99蜜桃 | 狠狠色婷婷综合天天久久丁香 | 久久精品国产精品亚洲毛片| 国产精品久久久久久久久久影院| 亚洲精品综合久久| 久久综合久久鬼色| 久久九九久精品国产免费直播| 嫩草影院久久99| 青青热久久综合网伊人| 热99re久久国超精品首页| 香蕉久久一区二区不卡无毒影院 | 久久人人爽爽爽人久久久| 久久精品国产亚洲AV电影| 久久精品国产网红主播| 久久国产精品一区二区| 国产精品免费久久久久影院| 久久久精品久久久久久|