Brow, which came to mind at the moment was the creation of two functions:
Status_Product : Returns the value of the field qt_previs or qt_edido for a given product on a day Specific, depending on the P_TIPO variable;
My_Consult : Returns the data you want, restricting the dates to a supplied interval. As for the performance, it can leave to be desired, take a test, maybe you can improve this code.
A detail: The header, with the dates values, is on your account, okay?
The first function:
Select all
FUNCTION status_produto (
p_cd_produto IN NUMBER,
p_dat VARCHAR2,
p_tipo IN NUMBER
)
RETURN NUMBER IS
p_quant NUMBER;
BEGIN
SELECT NVL (DECODE (p_tipo, 0, qt_previsto, qt_pedido), 0)
INTO p_quant
FROM tabela
WHERE cd_produto = p_cd_produto
AND TRUNC (dt_pedido) = TO_DATE (p_dat, 'dd/mm/yyyy');
RETURN p_quant;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 0;
END;
The main function:
1]]
Yes, CR_Cursor is a generic cursor:
I hope this helps.