Перепиши скрипт c pl/sql на pl/pgsql declare custlimit plsinteger := 1000; cursor…
- User
Перепиши скрипт c pl/sql на pl/pgsql
declare cust_limit pls_integer := 1000; cursor cust_cursor is select distinct c.cust_id from cam_int_customers c where prt_mcard_idtp_id is null and (prt_mcard_series is not null or prt_mcard_num is not null or prt_mcard_date_of_issue is not null or prt_mcard_valid_for is not null); type customer_t is table of cust_cursor%rowtype; cust customer_t; begin
open cust_cursor; loop fetch cust_cursor bulk collect into cust limit cust_limit;
exit when cust.count = 0; forall i in 1 .. cust.count update cam_int_customers c set prt_mcard_idtp_id = 14 where c.cust_id = cust(i).cust_id and prt_mcard_idtp_id is null and (prt_mcard_series is not null or prt_mcard_num is not null or prt_mcard_date_of_issue is not null or prt_mcard_valid_for is not null); commit;end loop;
end;
- Assistant
Перепишем ваш скрипт с PL/SQL на PL/pgSQL:
DO $$ DECLARE cust_limit integer := 1000; cust_cursor CURSOR FOR SELECT DISTINCT c.cust_id FROM cam_int_customers c WHERE prt_mcard_idtp_id IS NULL AND (prt_mcard_series IS NOT NULL OR prt_mcard_num IS NOT NULL OR prt_mcard_date_of_issue IS NOT NULL OR prt_mcard_valid_for IS NOT NULL); TYPE customer_t IS TABLE OF RECORD (cust_id integer); cust customer_t; BEGIN OPEN cust_cursor; LOOP FETCH cust_cursor INTO cust FOR cust_limit ROWS; EXIT WHEN NOT FOUND; FOR i IN 1 .. array_length(cust, 1) LOOP UPDATE cam_int_customers c SET prt_mcard_idtp_id = 14 WHERE c.cust_id = cust[i].cust_id AND prt_mcard_idtp_id IS NULL AND (prt_mcard_series IS NOT NULL OR prt_mcard_num IS NOT NULL OR prt_mcard_date_of_issue IS NOT NULL OR prt_mcard_valid_for IS NOT NULL); END LOOP; COMMIT; END LOOP; CLOSE cust_cursor; END $$;