P. 1
Apostila Completa Oracle 9i

Apostila Completa Oracle 9i

4.0

|Views: 3,585|Likes:
Published by Willian

More info:

Published by: Willian on Jul 22, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

11/30/2012

pdf

text

original

Quando houver um COMMIT dentro de um loop de cursor SELECT ... FOR
UPDATE, quaisquer tentativa de busca após o COMMIT retornará erro ORA-1002 pois o
cursor é invalidado após essa operação para liberar os bloqueios nas linhas das tabelas.
Contudo, você pode utilizar a chave primária da tabela na cláusula WHERE de UPDATE,
como ilustrado pelo seguinte exemplo:

DECLARE

v_NumCredits classes.num_credits%TYPE;

CURSOR c_RegisteredStudents IS
SELECT *
FROM students
WHERE id IN (SELECT student_id
FROM registered_students
WHERE department= 'HIS'
AND course = 101);

BEGIN

FOR v_StudentInfo IN c_RegisteredStudents LOOP

SELECT num_credits
INTO v_NumCredits
FROM classes
WHERE department = 'HIS'
AND course = 101;

76

UPDATE students
SET current_credits = current_credits + v_NumCredits
WHERE id = v_Studentinfo.id;

COMMIT;
END LOOP;

END;
/

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->