Oracle case函數(shù)使用介紹
1.創(chuàng)建測(cè)試表:
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ù)
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.更新語句
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é)果
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 語句的用法詳解
- Oracle數(shù)據(jù)庫(kù)的備份與恢復(fù)
- Oracle誤刪除表數(shù)據(jù)后的數(shù)據(jù)恢復(fù)詳解
- oracle冷備份恢復(fù)和oracle異機(jī)恢復(fù)使用方法
- oracle如何恢復(fù)被覆蓋的存儲(chǔ)過程
- 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)記錄
相關(guān)文章
oracle數(shù)據(jù)庫(kù)密碼到期怎么解決
這篇文章主要介紹了oracle數(shù)據(jù)庫(kù)密碼到期的解決方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下2017-02-02Oracle平臺(tái)應(yīng)用數(shù)據(jù)庫(kù)系統(tǒng)的設(shè)計(jì)與開發(fā)
Oracle平臺(tái)應(yīng)用數(shù)據(jù)庫(kù)系統(tǒng)的設(shè)計(jì)與開發(fā)...2007-03-03利用windows任務(wù)計(jì)劃實(shí)現(xiàn)oracle的定期備份
我們搞數(shù)據(jù)庫(kù)管理系統(tǒng)的經(jīng)常會(huì)遇到數(shù)據(jù)庫(kù)定期自動(dòng)備份的問題,有各種各樣的方法,這里介紹一種利用windows任務(wù)計(jì)劃實(shí)現(xiàn)oracle定期備份的方法供大家分享。2009-08-08oracle impdp network_link參數(shù)使用介紹
本文將介紹oracle impdp network_link參數(shù)使用方法,需要了解更多的朋友可以參考下2012-11-11oracle中dblink查看、創(chuàng)建、使用以及刪除實(shí)例代碼
當(dāng)用戶要跨本地?cái)?shù)據(jù)庫(kù)訪問另外一個(gè)數(shù)據(jù)庫(kù)表中的數(shù)據(jù)時(shí),本地?cái)?shù)據(jù)庫(kù)中必須創(chuàng)建了遠(yuǎn)程數(shù)據(jù)庫(kù)的DBLINK,下面這篇文章主要給大家介紹了關(guān)于oracle中dblink查看、創(chuàng)建、使用以及刪除的相關(guān)資料,需要的朋友可以參考下2022-04-04