UPDATE Statement doesn't update any row

757 Views Asked by At

I got two tables (ORACLE): D_CONTROL_CARGA and F_PS_CARGA_DIARIA_D

SELECT control_id, control_cd, control_query_tx 
FROM ONHR_DIM.D_CONTROL_CARGA;

table D_CONTROL_CARGA

SELECT FECHA_ID, CONTROL_ID, CONTROL_CD, CANTIDAD_CA 
FROM onhr_dim.F_PS_CARGA_DIARIA_D;

table F_PS_CARGA_DIARIA_D

I want to update the column CANTIDAD_CA with this PL/SQL code:

DECLARE
sql_qry ONHR_DIM.D_CONTROL_CARGA.control_query_tx%TYPE;
cantidad_ca ONHR_DIM.F_PS_CARGA_DIARIA_D.CANTIDAD_CA%TYPE;
CURSOR cQueries IS SELECT control_id,control_query_tx FROM ONHR_DIM.D_CONTROL_CARGA;
BEGIN
   FOR reg IN cQueries LOOP
        sql_qry:=SUBSTR(reg.control_query_tx, 0, LENGTH(reg.control_query_tx) - 1);
        IF sql_qry not like '%to_char(sysdate%' THEN 
           execute immediate sql_qry into cantidad_ca;
           UPDATE ONHR_DIM.F_PS_CARGA_DIARIA_D SET CANTIDAD_CA=cantidad_ca WHERE CONTROL_ID=reg.control_id AND FECHA_ID=TRUNC(SYSDATE);        
        END IF;
    END LOOP;
END;

Then I got: Updated Rows -1

What Do I have to change?

0

There are 0 best solutions below