skid
03-05-2003, 05:05 AM
Hi all,
I have this table:
TEXT_ID CUST_NO EMP_NO TYPE FLAG
---------- ---------- ---------- ------ ------
1000 1
1002 2
1003 3
1004 4
and I have this cursor below, where either V_CUST_NO or V_EMP_NO
can have a value (the other must be null). For single value (v_emp_no =3, v_cust_no = null), my query works, but if i want to select for all cust_no, emp_no (v_cust_no = null, v_emp_no = null) it doesn't return records. I have experimented with decode and nvl, but can't seem to find a solution.
DECLARE
V_CUST_NO NUMBER := NULL;
V_EMP_NO NUMBER := NULL;
BEGIN
DBMS_OUTPUT.PUT_LINE('TEXT_ID CUST_NO EMP_NO');
FOR REC IN (SELECT TEXT_ID, CUST_NO, EMP_NO
FROM TEXT
WHERE DECODE(CUST_NO, NULL, EMP_NO, CUST_NO) =
DECODE(V_CUST_NO, NULL, V_EMP_NO, V_CUST_NO)
)
LOOP
DBMS_OUTPUT.PUT_LINE (
(REC.TEXT_ID||' '||REC.CUST_NO||' '||REC.EMP_NO);
END LOOP;
END;
TIA,
skid
I have this table:
TEXT_ID CUST_NO EMP_NO TYPE FLAG
---------- ---------- ---------- ------ ------
1000 1
1002 2
1003 3
1004 4
and I have this cursor below, where either V_CUST_NO or V_EMP_NO
can have a value (the other must be null). For single value (v_emp_no =3, v_cust_no = null), my query works, but if i want to select for all cust_no, emp_no (v_cust_no = null, v_emp_no = null) it doesn't return records. I have experimented with decode and nvl, but can't seem to find a solution.
DECLARE
V_CUST_NO NUMBER := NULL;
V_EMP_NO NUMBER := NULL;
BEGIN
DBMS_OUTPUT.PUT_LINE('TEXT_ID CUST_NO EMP_NO');
FOR REC IN (SELECT TEXT_ID, CUST_NO, EMP_NO
FROM TEXT
WHERE DECODE(CUST_NO, NULL, EMP_NO, CUST_NO) =
DECODE(V_CUST_NO, NULL, V_EMP_NO, V_CUST_NO)
)
LOOP
DBMS_OUTPUT.PUT_LINE (
(REC.TEXT_ID||' '||REC.CUST_NO||' '||REC.EMP_NO);
END LOOP;
END;
TIA,
skid