亚洲欧洲国产欧美一区精品,激情五月亚洲色五月,最新精品国偷自产在线婷婷,欧美婷婷丁香五月天社区

      考試首頁 | 考試用書 | 培訓(xùn)課程 | 模擬考場 | 考試論壇  
      全國  |             |          |          |          |          |         
        當(dāng)前位置:計(jì)算機(jī)等級 > 二級考試 > Java語言程序設(shè)計(jì) > 考試輔導(dǎo) > 文章內(nèi)容
        

      全國計(jì)算機(jī)等級考試二級Java重點(diǎn)內(nèi)容(10)

      中華IT學(xué)院   【 】  [ 2016年9月18日 ]

      單行函數(shù)計(jì)算

      nvl(bonus, 0)

      upper(job) = 'ANALYST'

      round(salary, 2)

      to_char(sysdate, 'yyyy/mm/dd')

      to_date('2012-01-12','yyyy-mm-dd')

      select ename, salary, bonus,

      coalesce(bonus, salary * 0.5, 100)

      as bo

      from emp_ning;

      coalesce(list):

      返回參數(shù)列表中第一個(gè)非空值

      0-9分

      create table ielts_ning(name char(10),s1 number(2,1),s2 number(2,1),s3 number(2,1),s4 number(2,1));

      insert into ielts_ning values('A', 8, 8, 6, 7);

      insert into ielts_ningvalues('B', 6, 6, 7, 7);

      insert into ielts_ningvalues('C', 6, 7, 7, 7);

      insert into ielts_ningvalues('D', 8, 6.5, 6, 6);

      姓名 聽力 閱讀 寫作 口語 總分

      name  s1  s2   s3    s4

            number(2,1)

      張三 8    8    6     7  7.25-> 7.5

      李四 6    6    7     7  6.5 -> 6.5

           6    7    7     7  6.75-> 7

                              6.125 -> 6

                              6.625  6.5

      [0, 0.25) [0.25, 0.75) [0.75, 1)

         0            0.5       1

      select name, s1, s2, s3,s4,

            (s1+s2+s3+s4)/4  s

      from ielts_ning;

      7.25

      整數(shù)位: trunc((s1+s2+s3+s4)/4) -> 7

      小數(shù):mod((s1+s2+s3+s4)/4, 1) -> 0.25

      select name, s1, s2, s3, s4,

      trunc((s1+s2+s3+s4)/4) +

      case when mod((s1+s2+s3+s4)/4, 1) < 0.25       then 0

           when mod((s1+s2+s3+s4)/4,1)>=0.25              and 

                mod((s1+s2+s3+s4)/4,1)<0.75

           then 0.5

           when mod((s1+s2+s3+s4)/4, 1) >= 0.75      then 1

      end as total_s

      from ielts_ning;

      double calculate(double score){

          int i = trunc(score);//整數(shù)

          double j = mod(score, 1); //小數(shù)

          double result = 0;

          if (j < 0.25)

             result = i;

          else if ( j >= 0.25 && j < 0.75)

             result = i + 0.5;

          else if ( j >= 0.75)

             result = i + 1;

          return result;

      }

      create or replace function calculate_ning(score number)

      return number

      is

        --定義變量

        i number; --整數(shù)

        j number; --小數(shù)

        result number; --返回結(jié)果

      begin

        --程序體

        i := trunc(score); --數(shù)據(jù)庫中賦值:=

        j := mod(score, 1);

        if j < 0.25 then

           result := 0;

        elsif j >= 0.25 and j < 0.75 then

           result := 0.5;

        elsif j >= 0.75 then

           result := 1;

        end if;

        return i + result;

      end;

      /

      Function Created. 表示創(chuàng)建成功

      Function Created  with Compil...編譯錯(cuò)誤

      SQL>show errors 檢查錯(cuò)誤信息

      修改后, 再次執(zhí)行, 直到創(chuàng)建成功為止

      --函數(shù)建立以后,在sql語句中使用

      select name, s1, s2, s3, s4, calculate_ning((s1 + s2 + s3 + s4) / 4) from ielts_ning;

      --當(dāng)數(shù)據(jù)庫中提供的函數(shù)不夠用時(shí),可以創(chuàng)建自己的函數(shù)

      --和java中定義自己的方法是一樣的道理.

      nvl                     length()

      upper                   iterator()

      round                   indexOf()

      calcaulate_ning         random()

      .....                   code15To18()

      第一部分: SQL 語句

      第二部分: PL/SQL: 在數(shù)據(jù)庫中編程

                 包括:funcation 函數(shù)

                      procedure 過程

                      package   包

                      trigger   觸發(fā)器

      select ename, job, salary,

      case job when 'clerk' then salary * 1.05

               when 'Programmer' then salary * 1.1

               when 'Analyst' then salary * 1.15

               else salary

      end as new_sal

      from emp_ning;

      --用case實(shí)現(xiàn)

      case when job = 'clerk' then salary * 1.05

           when job = 'Programmer' then salary*1.1

           when job = 'Analyst' then salary * 1.15

           else salary

      end

      --用decode函數(shù)實(shí)現(xiàn)

      select ename, job, salary,

      decode(upper(job), 'CLERK', salary * 1.05,

                  'PROGRAMMER', salary * 1.1,

                  'ANALYST', salary * 1.15,

                  salary) as new_sal

      from emp_ning;

      分享到:
      本文糾錯(cuò)】【告訴好友】【打印此文】【返回頂部
      將考試網(wǎng)添加到收藏夾 | 每次上網(wǎng)自動(dòng)訪問考試網(wǎng) | 復(fù)制本頁地址,傳給QQ/MSN上的好友 | 申請鏈接 | 意見留言 TOP
      關(guān)于本站  網(wǎng)站聲明  廣告服務(wù)  聯(lián)系方式  站內(nèi)導(dǎo)航  考試論壇
      Copyright © 2007-2013 中華考試網(wǎng)(Examw.com) All Rights Reserved