I have a function in which I'm querying data according to the passed on variables as follows:
CREATE OR REPLACE FUNCTION IR.SRG (
IR_item IN VARCHAR2,
IR_comp VARCHAR2,
IR_locn VARCHAR2,
IR_Type VARCHAR2,
IR_fromdate DATE,
IR_tilldate DATE
)
RETURN NUMBER
DETERMINISTIC
IS
IR_qty NUMBER;
BEGIN
IF IR_Type = 'O'
THEN
SELECT SUM(QTY)
INTO IR_qty
FROM STOCK_LEDGER
WHERE
ITEM_CODE = IR_item AND
LOCATION_CODE IN
DECODE(IR_locn,
'ALL',
'('
|| '''D2'', ''D4'', ''D5'', ''D11'''
|| ')',
'(' || IR_locn || ')')
AND DOCUMENTDATE <= IR_TILLDATE
AND DOCUMENTDATE >= IR_FROMDATE;
END IF;
RETURN (NVL (IR_QTY, 0));
EXCEPTION
WHEN ZERO_DIVIDE
THEN
RETURN 0;
END;
/
If the user passes D2
for the IR_locn
parameter then the query should run for that particular location, if the user passes ALL
, then the query should run for the four locations D2, D4, D5,D11
as specified.
I am not able to achieve it by using IN
, the data returns no records.
I tried running the query using DUAL
and the format for the IN
clause looks fine.
Select DECODE ('ALL',
'ALL',
'('
|| '''D2'', ''D4'', ''D5'', ''D11'''
|| ')',
'(' || 'D5' || ')'
) FROM DUAL
I am getting the results as follows as I am running it with ALL
:
('D2', 'D4', 'D5', 'D11')