小问题 初学
DECLARE
v_Majorstudents.major%TYPE;
v_CreditIncreaseNUMBER := 3;
BEGIN
v_Major := 'History';
UPDATE students
SET current_credits = current_credits + v_CreditIncrease
WHERE major = v_Major;
END;
/
2.
DECLARE
v_StudentIDstudents.id%TYPE;
BEGIN
SELECT student_sequence.NEXTVAL
INTO v_StudentID
FROM dual;
INSERT INTO students (id, first_name, last_name)
VALUES (v_StudentID, 'Timothy', 'Taller');
INSERT INTO students (id, first_name, last_name)
VALUES (student_sequence.NEXTVAL, 'Patrick', 'Poll');
END
请帮忙分析一下这两段代码分别完成什么工作 谢谢哈
------解决方案--------------------第一段代码:
更新students表,
第二段代码:
先取出student_sequence.NEXTVAL,存到变量v_StudentID中;
再往students 写入数据。
------解决方案--------------------你不会把空格写写好?定义变量能这么连着写吗?
------解决方案--------------------DECLARE
v_Majorstudents.major%TYPE;
v_CreditIncreaseNUMBER := 3;
BEGIN
v_Major := 'History';
UPDATE students
SET current_credits = current_credits + v_CreditIncrease
WHERE major = v_Major;
END;
--UPDATE students
SET current_credits = current_credits + 3
WHERE major = 'History';
更新 students major = 'History' 将current_credits = current_credits + 3
DECLARE
v_StudentIDstudents.id%TYPE;
BEGIN
SELECT student_sequence.NEXTVAL
INTO v_StudentID
FROM dual;
INSERT INTO students (id, first_name, last_name)
VALUES (v_StudentID, 'Timothy', 'Taller');
INSERT INTO students (id, first_name, last_name)
VALUES (student_sequence.NEXTVAL, 'Patrick', 'Poll');
END
--INSERT INTO students (id, first_name, last_name)
VALUES (student_sequence.NEXTVAL, 'Timothy', 'Taller');
INSERT INTO students (id, first_name, last_name)
VALUES (student_sequence.NEXTVAL, 'Patrick', 'Poll');
students 插入二条记录
------解决方案--------------------DECLARE
v_Majorstudents.major%TYPE;
v_CreditIncreaseNUMBER := 3;
BEGIN
v_Major := 'History';
UPDATE students
SET current_credits = current_credits + v_CreditIncrease
WHERE major = v_Major;
END;
--UPDATE students
SET current_credits = current_credits + 3
WHERE major = 'History';
更新 students major = 'History' 将current_credits = current_credits + 3
DECLARE
v_StudentIDstudents.id%TYPE;
BEGIN
SELECT student_sequence.NEXTVAL
INTO v_StudentID
FROM dual;
INSERT INTO students (id, first_name, last_name)
VALUES (v_StudentID, 'Timothy', 'Taller');
INSERT INTO students (id, first_name, last_name)
VALUES (student_sequence.NEXTVAL, 'Patrick', 'Poll');
END
--INSERT INTO students (id, first_name, last_name)
VALUES (student_sequence.NEXTVAL, 'Timothy', 'Taller');
INSERT INTO students (id, first_name, last_name)
VALUES (student_sequence.NEXTVAL, 'Patrick', 'Poll');
students 插入二条记录
------解决方案--------------------DECLARE
v_Majorstudents.major%TYPE;
v_CreditIncreaseNUMBER := 3;
BEGIN
v_Major := 'History';
UPDATE students
SET current_credits = current_credits + v_CreditIncrease
WHERE major = v_Major;
END;
--UPDATE students
SET current_credits = current_credits + 3
WHERE major = 'History';
更新 students major = 'History' 将current_credits = current_credits + 3
DECLARE
v_StudentIDstudents.id%TYPE;
BEGIN
SELECT student_sequence.NEXTVAL
INTO v_StudentID
FROM dual;
INSERT INTO students (id, first_name, last_name)
VALUES (v_StudentID, 'Timothy', 'Taller');
INSERT INTO students (id, first_name, last_name)