DECLARE
partyId VARCHAR2(20);
CURSOR c_party_group is select party_id from PARTY_GROUP;
attrCount integer;
BEGIN
OPEN c_party_group;
LOOP
FETCH c_party_group into partyId;
exit when c_party_group%notfound;
dbms_output.put_line(partyId);
SELECT COUNT (*) INTO attrCount FROM PARTY_ATTRIBUTE WHERE PARTY_ID = partyId and attr_name = 'LEVEL';
if attrCount = 0 then
insert into party_attribute (party_id, attr_name, attr_value) values (partyId, 'LEVEL', '4');
end if;
END LOOP;
CLOSE c_party_group;
END;