oracle的case函式和case控制結構

jss001發表於2009-03-06
create sequence STUDENT_SEQUENCE;

CREATE TABLE students (
id NUMBER(5) PRIMARY KEY,
stu_name VARCHAR2(20),
score NUMBER(10,0),
grade varchar2(2));

INSERT INTO students (id, stu_name, score, grade)
VALUES (student_sequence.NEXTVAL, 'Scott', 98,null);

INSERT INTO students (id, stu_name, score, grade)
VALUES (student_sequence.NEXTVAL, 'Margaret', 88,null);

INSERT INTO students (id, stu_name, score, grade)
VALUES (student_sequence.NEXTVAL, 'Joanne', 75,null);

INSERT INTO students (id, stu_name, score, grade)
VALUES (student_sequence.NEXTVAL, 'Manish', 66,null);


update students
set grade =
case when score > 90 then 'a'
when score > 80 then 'b'
when score > 70 then 'c'
else 'd' end

oracle的case結構

begin
case when 2<1 then
dbms_output.put_line('y');
else
dbms_output.put_line('n');
end case;
end;
/

這個case when ... end case 和上邊的case when ... end是不同的。

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18921899/viewspace-1016956/,如需轉載,請註明出處,否則將追究法律責任。

相關文章