主頁(yè) > 知識(shí)庫(kù) > Oracle case函數(shù)使用介紹

Oracle case函數(shù)使用介紹

熱門標(biāo)簽:鐵路電話系統(tǒng) 服務(wù)外包 AI電銷 呼叫中心市場(chǎng)需求 Linux服務(wù)器 地方門戶網(wǎng)站 網(wǎng)站排名優(yōu)化 百度競(jìng)價(jià)排名

1.創(chuàng)建測(cè)試表:

復(fù)制代碼 代碼如下:

DROP SEQUENCE student_sequence;
CREATE SEQUENCE student_sequence  START WITH 10000  INCREMENT BY 1;

DROP TABLE students;
CREATE TABLE students (
  id               NUMBER(5) PRIMARY KEY,
  first_name       VARCHAR2(20),
  last_name        VARCHAR2(20),
  major            VARCHAR2(30),
  current_credits  NUMBER(3),
  grade     varchar2(2));

INSERT INTO students (id, first_name, last_name, major, current_credits,grade)
  VALUES (student_sequence.NEXTVAL, 'Scott', 'Smith', 'Computer Science', 98,null);

INSERT INTO students (id, first_name, last_name, major, current_credits,grade)
  VALUES (student_sequence.NEXTVAL, 'Margaret', 'Mason', 'History', 88,null);

INSERT INTO students (id, first_name, last_name, major, current_credits,grade)
  VALUES (student_sequence.NEXTVAL, 'Joanne', 'Junebug', 'Computer Science', 75,null);

INSERT INTO students (id, first_name, last_name, major, current_credits,grade)
  VALUES (student_sequence.NEXTVAL, 'Manish', 'Murgratroid', 'Economics', 66,null);

commit;

2.查看相應(yīng)數(shù)據(jù)

復(fù)制代碼 代碼如下:

SQL> select * from students;

        ID FIRST_NAME           LAST_NAME            MAJOR                          CURRENT_CREDITS GR
---------- -------------------- -------------------- ------------------------------ --------------- --
     10000 Scott                Smith                Computer Science                            98
     10001 Margaret             Mason                History                                     88
     10002 Joanne               Junebug              Computer Science                            75
     10003 Manish               Murgratroid          Economics                                   66

3.更新語(yǔ)句

復(fù)制代碼 代碼如下:

update students
set grade = (
select grade from
(
select id,
case when current_credits > 90 then 'a'
     when current_credits > 80 then 'b'
     when current_credits > 70 then 'c'
else 'd' end grade
from students
) a
where a.id = students.id
)
/

4.更新后結(jié)果

復(fù)制代碼 代碼如下:

SQL> select * from students;

        ID FIRST_NAME           LAST_NAME            MAJOR                          CURRENT_CREDITS GR
---------- -------------------- -------------------- ------------------------------ --------------- --
     10000 Scott                Smith                Computer Science                            98 a
     10001 Margaret             Mason                History                                     88 b
     10002 Joanne               Junebug              Computer Science                            75 c
     10003 Manish               Murgratroid          Economics                                   66 d

您可能感興趣的文章:
  • oracle case when 語(yǔ)句的用法詳解
  • Oracle數(shù)據(jù)庫(kù)的備份與恢復(fù)
  • Oracle誤刪除表數(shù)據(jù)后的數(shù)據(jù)恢復(fù)詳解
  • oracle冷備份恢復(fù)和oracle異機(jī)恢復(fù)使用方法
  • oracle如何恢復(fù)被覆蓋的存儲(chǔ)過(guò)程
  • rman恢復(fù)方案和oracle異機(jī)恢復(fù)
  • Oracle數(shù)據(jù)庫(kù)數(shù)據(jù)丟失恢復(fù)的幾種方法總結(jié)
  • oracle drop table(表)數(shù)據(jù)恢復(fù)方法
  • oracle數(shù)據(jù)庫(kù)創(chuàng)建備份與恢復(fù)腳本整理
  • 一次簡(jiǎn)單的Oracle恢復(fù)Case實(shí)戰(zhàn)記錄

標(biāo)簽:湘潭 湖南 衡水 蘭州 銅川 黃山 崇左 仙桃

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Oracle case函數(shù)使用介紹》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266