Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: 2 problems in using package........
Hi Jimmy,
I don´t know how to solve your problem, but try another technic for your update
create or replace package body update_ccc is procedure p_update_ccc is begin FOR R_TTT IN (Select ID from TTT) LOOP IF R_TTT.ID = 1 THEN update TTT set CCC = 1 where ID = R_TTT.ID; ELSE update TTT set CCC = 2 where ID = R_TTT.ID; END IF; COMMIT; end loop; end; end update_ccc;
Now you haven´t to open, fetch and close the cursor. The cursor is in the text more readable than in the declare-section, and you have no exception handling like "When Others then Close Cursor" ! This cursor is a FOR-RECORD-IN-SELECT-STATEMENT-CURSOR. But why do you didn´t update this example with
UPDATE TTT SET
CCC = decode (ID, 1, 1, 2);
That´s all. This decode means: IF ID is '1' then result is '1' else '2'. You can make this statements as long as you want. DECODE (COL_x, value_1, result_1 [, value_2, result_2] [, ELSE_Value]). But decode only works in SQL, not in PL/SQL
Bye
Gerd Volberg
Received on Tue Aug 18 1998 - 00:00:00 CDT