Skip to content

Instantly share code, notes, and snippets.

@obedmhg
Created May 19, 2016 14:32
Show Gist options
  • Save obedmhg/27e73479316b4670452147eac0a1a9af to your computer and use it in GitHub Desktop.
Save obedmhg/27e73479316b4670452147eac0a1a9af to your computer and use it in GitHub Desktop.
With this PL/SQL you can find which records on your DCS_PRD_CHLDSKU table are missing a sequence, is is an edge case, but when it happens you need to go and find them and fix them otherwise your deployment will be stuck, this will help you to do it for all your products.
DECLARE
CURSOR c_get_all_products
IS
SELECT DISTINCT(product_id) FROM DCS_PRD_CHLDSKU;
seq_max NUMBER;
seq_count NUMBER;
broken_count NUMBER;
BEGIN
broken_count := 0;
FOR product_id IN c_get_all_products
LOOP
SELECT COUNT(*)
INTO seq_count
FROM DCS_PRD_CHLDSKU
WHERE PRODUCT_ID = product_id.product_id
ORDER BY SEQUENCE_NUM;
SELECT MAX(SEQUENCE_NUM) + 1
INTO seq_max
FROM DCS_PRD_CHLDSKU
WHERE PRODUCT_ID = product_id.product_id
ORDER BY SEQUENCE_NUM;
IF seq_max <> seq_count THEN
DBMS_OUTPUT.PUT_LINE(product_id.product_id || ' seq_count=' || seq_count || ' seq_max=' || seq_max);
broken_count := broken_count + 1;
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE(broken_count || ' records have broken sequence');
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment