Обновление записи с Oracle SQL приводит к бесконечному l oop при использовании курсора - PullRequest
0 голосов
/ 05 февраля 2020

Я застрял в бесконечном l oop при использовании курсора для обновления записи. Вот код ... Любые предложения о том, что я должен делать?

CREATE OR REPLACE PROCEDURE SHADI.filling_conditional
as
  cursor filling_cursor is select * from deposits_table for update;
begin 
  for i in filling_cursor 
  loop       
       update deposits_table 
         set conditional_flag = case 
                                    when i.deposit_amount > 1000 and i.currency_code = 'JOD'
                                         and (select customer_info.sex 
                                              from customer_info 
                                              where customer_info.customer_number = i.customer_number) = 1 
                                       then 1
                                    else 0 
                                 end;

  end loop;
end filling_conditional;
/

1 Ответ

0 голосов
/ 05 февраля 2020

Пожалуйста, попробуйте следующий код процедуры:

CREATE OR REPLACE PROCEDURE SHADI.filling_conditional
as
   c_deposit_amount   deposits_table.deposit_amount%type; 
   c_currency_code deposits_table.currency_code%type; 
   c_customer_number deposits_table.customer_number%type; 
   cursor filling_cursor is select deposit_amount, currency_code, customer_number from deposits_table for update;
BEGIN 
   OPEN filling_cursor; 
   LOOP 
   FETCH filling_cursor into c_deposit_amount, c_currency_code, c_customer_number; 
      EXIT WHEN filling_cursor%notfound; 
      update deposits_table 
         set conditional_flag = case 
                                    when c_deposit_amount > 1000 and c_currency_code = 'JOD'
                                         and (select customer_info.sex 
                                              from customer_info 
                                              where customer_info.customer_number = c_customer_number) = 1 
                                       then 1
                                    else 0 
                                 end;
   END LOOP; 
   CLOSE filling_cursor; 
END filling_conditional;
/
...