0

I am new to pl/sql and I got stuck. I have a table consisting of 3 columns: package_uid, csms_package_id and flag. First two columns are filled and the third is empty. Flag column is filled when a procedure is called in a way that procedure compares package_id-s from that table and another table and if they are a match, the flag should be 'YES'. This is my code:

DECLARE
  package_uid varchar2(256);
  CURSOR abc IS SELECT csms_package_id, PACKAGE_UID, FLAG FROM table1 tpc;
  CURSOR defg IS SELECT package_id FROM table2 tpc2;
BEGIN
  for i in abc  loop
    for j in defg loop
      begin
        if i.CSMS_PACKAGE_ID=j.package_id THEN
          i.flag := 'YES' ;
          DBMS_OUTPUT.PUT_LINE(i.flag);
        end if;
      end;
    end loop;
  end loop;

end;

The output writes 'yes' correct number of times but my table is not updated with 'yes' values. How can I update flag values in the table?

1 Answer 1

3

You aren't updating anything; if you want to do that, you'll have to use UPDATE or MERGE statement.

Though, why PL/SQL and why nested loops? That looks highly inefficient. How about a simple & single merge instead?

MERGE INTO table1 a
     USING table2 b
        ON (a.package_uid = b.package_id)
WHEN MATCHED
THEN
   UPDATE SET a.flag = 'YES';
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks pal! Why nested loops? Bcz I'm a newbie. Thanks for your help, very much appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.