oracle-databasestored-proceduresplsqlprocedureoracle-ebs

Multiple Records being fetched in Cursor PLSQL Procedure


Table : WSH_DEL_DETAILS_INTERFACE

Unique Column:DELIVERY_DETAIL_INTERFACE_ID

Input to procedure : DELIVERY_DETAIL_INTERFACE_ID

Column values to be fetched:SALES_ORDER_LINE_NUMBER , SALES_ORDER_NUMBER

Expected Output: Single record

Actual Output: All records in table are being fetched

Code:

create or replace PROCEDURE procedurevalidation(
delivery_detail_interface_id IN 
WSH_DEL_DETAILS_INTERFACE.DELIVERY_DETAIL_INTERFACE_ID%TYPE,
ROW_COUNT OUT INTEGER)
IS
CURSOR wddi_cur IS SELECT *  FROM WSH_DEL_DETAILS_INTERFACE WHERE 
DELIVERY_DETAIL_INTERFACE_ID = delivery_detail_interface_id;
wddi_record WSH_DEL_DETAILS_INTERFACE%ROWTYPE;

BEGIN

OPEN wddi_cur;

LOOP

FETCH wddi_cur into wddi_record;
EXIT when wddi_cur%NOTFOUND;

DBMS_OUTPUT.ENABLE(100000);
DBMS_OUTPUT.PUT_LINE(delivery_detail_interface_id);

DBMS_OUTPUT.PUT_LINE('SALESORDERNUMBER111:::: ' || 
wddi_record.SALES_ORDER_NUMBER);
DBMS_OUTPUT.PUT_LINE('SALESORDERLINENUMBER1111::::: ' || 
wddi_record.SALES_ORDER_LINE_NUMBER);
DBMS_OUTPUT.PUT_LINE('COUNT' || ROW_COUNT);

END LOOP;
CLOSE wddi_cur;


end;

Solution

  • You need to change the names of the input variable to your procedure.

    create or replace PROCEDURE procedurevalidation(
    p_delivery_detail_interface_id IN 
    WSH_DEL_DETAILS_INTERFACE.DELIVERY_DETAIL_INTERFACE_ID%TYPE,
    ROW_COUNT OUT INTEGER)
    

    And in your cursor you need to change the variable name as well.

    CURSOR wddi_cur 
        IS 
    SELECT *  
      FROM WSH_DEL_DETAILS_INTERFACE 
     WHERE DELIVERY_DETAIL_INTERFACE_ID = p_delivery_detail_interface_id;
    

    Your cursor is returning all records in the table because you are equating the table's column itself and not matching it with the input variable in the procedure