Oracle - cursores

 
Vista:

cursores

Publicado por lauri (2 intervenciones) el 08/12/2003 12:07:24
Los cursores siempre tiene que ir select o puede ponerse update es decir
cursor t is select.... o se puede hacer
cursor t is update ....si se quiere cambiar algun campo
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:cursores

Publicado por PLAN (50 intervenciones) el 08/12/2003 19:53:48
Siempre de SELECT ...

Pero puedes hacer el SELECT y cuando esta en el FOR hacer el UPDATE del CURRENT ... o con el ROWID (traido en el SELECT)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:cursores

Publicado por JORGE SANCHEZ (186 intervenciones) el 08/12/2003 19:59:37
EJEMPLO ... SELECT - UPDATE CURRENT ...

DECLARE
CURSOR bin_cur(part_number NUMBER) IS
SELECT amt_in_bin FROM bins
WHERE part_num = part_number AND amt_in_bin > 0
ORDER BY bin_num
FOR UPDATE OF amt_in_bin;
bin_amt bins.amt_in_bin%TYPE;
total_so_far NUMBER(5) := 0;
amount_needed CONSTANT NUMBER(5) := 1000;
bins_looked_at NUMBER(3) := 0;
BEGIN
OPEN bin_cur(5469);
WHILE total_so_far < amount_needed LOOP
FETCH bin_cur INTO bin_amt;
EXIT WHEN bin_cur%NOTFOUND;
-- if we exit, there's not enough to fill the order
bins_looked_at := bins_looked_at + 1;
IF total_so_far + bin_amt < amount_needed THEN
UPDATE bins SET amt_in_bin = 0
WHERE CURRENT OF bin_cur;
-- take everything in the bin
total_so_far := total_so_far + bin_amt;
ELSE -- we finally have enough
UPDATE bins SET amt_in_bin = amt_in_bin
- (amount_needed - total_so_far)
WHERE CURRENT OF bin_cur;
total_so_far := amount_needed;
END IF;
END LOOP;

CLOSE bin_cur;
INSERT INTO temp
VALUES (NULL, bins_looked_at, '<- bins looked at');
COMMIT;
END;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar