如何编写查询来更新我的行'S'。我想更新当前的主键以更改它的数量。我不确定我是否需要子查询。 会更新分数,使用相同的方法更新“S”? “S”表示学号,“C”表示课程号。
我尝试但失败的查询是
update grades set s = 114 where s = 100;
'set s'是我想要更新的内容,'where s'正在查找具有该set's'数字的行。对?
这是我的查询,触发器和从等级中选择*看起来像。
create table grades (
S varchar2(12),
C varchar2(10),
Score number(3,0),
Letter_Grade char(1),
Constraint pk_grades primary key (S),
Constraint CK_grades check (score between 0 and 100)
constraint lg_grades check (letter_grade in ('A','B','C','D','F'))
);
SET SERVEROUTPUT ON
CREATE OR REPLACE TRIGGER MARK_BU
BEFORE UPDATE OF score ON grades
FOR EACH ROW
DECLARE
BEGIN
:NEW.letter_grade :=
CASE
WHEN :NEW.score >= 80 THEN 'A'
WHEN :NEW.score >= 70 THEN 'B'
WHEN :NEW.score >= 60 THEN 'C'
WHEN :NEW.score >= 50 THEN 'D'
ELSE 'F'
END ;
DBMS_OUTPUT.PUT_LINE ('Numeric_grade was updated to: ' || :NEW.score);
DBMS_OUTPUT.PUT_LINE ('Letter_grade was calculated to be:' || :NEW.letter_grade);
END;
S C SCORE L
------------ ---------- ---------- -
100 CST8255 49 F
101 CST8255 59 D
102 CST8255 69 C
103 CST8255 79 B
104 CST8255 89 A
答案 0 :(得分:0)
update grades set s = 114 where s = 100;
是否正确可行。