DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Using Function in Where Clause

Threaded View

  1. #1
    Join Date
    Feb 2003
    Posts
    4

    Question Using Function in Where Clause

    I have a function which returns a String of Numeric values. I chose a string variable as I can then return more than one set of values.

    I want to then use the sets of values I returned as an IN statement the WHERE clause of a SELECT SQL.

    However I keep getting Invalid Number. can someone show me how this be done?

    For example:
    FUNCTION F_FindOutstandingOrders(p_Date IN DATE)
    RETURN VARCHAR2 AS

    v_strReturnValue VARCHAR2(1000);

    CURSOR Cur_Orders (p_TXN_Date DATE) IS
    SELECT OrderNo
    FROM ORDERS
    WHERE Order_DATE BETWEEN p_TXN_Date - 14 AND p_TXN_Date + 14

    Rec_Orders Cur_Order%ROWTYPE;
    LOOP
    BEGIN
    FETCH Cur_Orders INTO Rec_Orders;
    EXIT WHEN Cur_Orders%NOTFOUND;
    IF Cur_Orders%ROWCOUNT = 1 THEN
    v_strReturnValue := Rec_Orders.OrderNo;
    ELSE
    v_strReturnValue := v_strReturnValue||', '||Rec_Orders.OrderNo;
    END IF;
    END;
    END LOOP;
    CLOSE Cur_Orders;

    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('EXCEPTION IN FUNCTION F_FindOutstandingOrders:'||SQLCODE||':'||SQLERRM);
    RETURN 'Error';
    END F_FindOutstandingOrders;

    If the funtion returned 734, 745, 748 where selected from Dual;

    But when I typed Select * from Payments Where Order_ID IN (F_FindOutstandingOrders(TO_DATE('22/01/2003', 'DD/MM'YYYY')
    /

    I get ERROR at line 1:
    ORA-01722: invalid number

    IF the fuction returned a single value then the query runs.
    Last edited by mjjrr1; 03-04-2003 at 09:30 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width