Home » SQL & PL/SQL » SQL & PL/SQL » Unable to pass date variables into a stored procedure (Oracle SQL)
Unable to pass date variables into a stored procedure [message #643165] Wed, 30 September 2015 13:57 Go to next message
emyk
Messages: 9
Registered: February 2010
Location: usa
Junior Member
I am getting blank when passing a date parameter into this stored procedure. I can get back some data if I hard code the date ranges.

can someone please provide some insight on this?

CREATE OR REPLACE PROCEDURE GET_USERS(startdate_in IN DATE, enddate_in IN DATE)
    IS
    BEGIN
    DELETE FROM TEMP_TABLE;
    INSERT INTO temp_table
    (ID, ROLE, DATE_USED, COUNT_S)
    SELECT    EMPLOYEE.CUSTOMERID as USER_ID,   'Customer' as ROLE_,  to_char (EMPLOYEE.STARTEDON, 'MM-YYYY') as REQ_MONTH, count (EMPLOYEE.SUBJECT) as SUBJ_COUNT 
    FROM     RCUSER.EMPLOYEE  EMPLOYEE     
    WHERE     EMPLOYEE.STATEID NOT IN (4,9,16,31,36) AND (EMPLOYEE.AGENTID=0)  AND (EMPLOYEE.STARTEDON >= to_date(startdate_in,'yyyy-mm-dd')) 
    AND (EMPLOYEE.STARTEDON < to_date(enddate_in,'yyyy-mm-dd'))  
    Group by CUSTOMERID, to_char (EMPLOYEE.STARTEDON, 'MM-YYYY')
    UNION
    SELECT    EMPLOYEE.PERFORMERID as USER_ID,   'Performer' as ROLE_,  to_char (EMPLOYEE.STARTEDON, 'MM-YYYY') as REQ_MONTH, count (EMPLOYEE.SUBJECT) as SUBJ_COUNT 
    FROM     RCUSER.EMPLOYEE          EMPLOYEE     
    WHERE     EMPLOYEE.PEID IN (1,4,6) AND EMPLOYEE.STATEID NOT IN (4,9,16,31,36) AND (EMPLOYEE.AGENTID=0)  AND (EMPLOYEE.STARTEDON >= to_date(startdate_in,'yyyy-mm-dd')) 
    AND (EMPLOYEE.STARTEDON < to_date(enddate_in,'yyyy-mm-dd')) 
    Group by PERFORMERID, to_char (EMPLOYEE.STARTEDON, 'MM-YYYY')
    UNION
    SELECT    EMPLOYEE.PERFORMERID as USER_ID,   'Approver' as ROLE_,  to_char (EMPLOYEE.STARTEDON, 'MM-YYYY') as REQ_MONTH, count (EMPLOYEE.SUBJECT) as SUBJ_COUNT 
    FROM     RCUSER.EMPLOYEE          EMPLOYEE    
    WHERE     EMPLOYEE.PEID IN (2,3) 
    AND EMPLOYEE.STATEID NOT IN (4,9,16,31,36) 
    AND (EMPLOYEE.AGENTID=0)  
    AND (EMPLOYEE.STARTEDON >= to_date(startdate_in,'yyyy-mm-dd')) 
    AND (EMPLOYEE.STARTEDON < to_date(enddate_in,'yyyy-mm-dd'))  
    Group by PERFORMERID, to_char (EMPLOYEE.STARTEDON, 'MM-YYYY');

END;
Re: Unable to pass date variables into a stored procedure [message #643166 is a reply to message #643165] Wed, 30 September 2015 14:22 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Interesting code, I guess.

What exactly do you expect or desire we do with this code?
Since we don't have your tables or data, about all we can do is look at it.

>to_date(startdate_in,'yyyy-mm-dd'))
NEVER, ever use TO_DATE() on any DATE datatype!
TO_DATE() converts a string to a DATE datatype.
Since STARTDATE_IN is already a DATE, then you can just use it.
Re: Unable to pass date variables into a stored procedure [message #643169 is a reply to message #643166] Wed, 30 September 2015 16:12 Go to previous message
emyk
Messages: 9
Registered: February 2010
Location: usa
Junior Member
ok, removing the to_date did the magic.

thanks.
Previous Topic: MERGE and SEQUENCE
Next Topic: Use of Force View
Goto Forum:
  


Current Time: Fri Apr 19 17:39:48 CDT 2024