Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8356389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:10:59+00:00 2026-06-09T10:10:59+00:00

Hi I have the following function created in Oracle. i will have to pass

  • 0

Hi I have the following function created in Oracle.
i will have to pass date-1 and date-2 parameters into the function and the function should return the another date to me .

please see the code below.

create or replace function GETD(p_d1   in date, 
                                p_d2   in date ) return DATE 
   as 
       l_result    DATE; 
   begin 
    SELECT EDIT_Date into l_result FROM qa.employees  WHERE qa.employee_join_date BETWEEN TO_DATE(p_d1, 'MM/DD/YYYY') AND TO_DATE(p_d2, 'MM/DD/YYYY') AND ROWNUM <= 1
    ;
       return l_result; 
  end; 

i execute the function as below

SELECT GETD('27-JUN-12','28-JUN-12') FROM DUAL

the function get compiled and while im passing the parameters to execute the function i get the following error “Not a Valid Month”.
Could some one please tell me where im going wrong

thanks
Justin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:11:00+00:00Added an answer on June 9, 2026 at 10:11 am

    First, you should not call TO_DATE on a date variable. If you do that, you force Oracle to first convert the date to a string using the session’s NLS_DATE_FORMAT and then convert the string back to a date using the specified format mask. If your NLS_DATE_FORMAT happens not to match the specified format mask (and, since the NLS_DATE_FORMAT is controlled by the client, some users and sessions will inevitably have a different date format), you’ll get an error.

    Assuming your intention was merely to ignore any time component, you should be using the trunc function instead.

    create or replace function GETD(p_d1   in date, 
                                    p_d2   in date ) 
      return DATE 
    as 
      l_result    DATE; 
    begin 
      SELECT EDIT_Date 
        into l_result 
        FROM qa.employees  
       WHERE qa.employee_join_date BETWEEN trunc(p_d1) AND trunc(p_d2) 
         AND ROWNUM <= 1;
    
      return l_result; 
    end; 
    

    The presence of a rownum <= 1 condition seems a bit odd– it seems unlikely that you really want to fetch an arbitrary row from the table that matches the employee_join_date criteria. Not knowing the requirements, it seems likely that you want to do something deterministic that fetches the row with the minimum (or maximum) edit_date.

    Second, when you call the function, you should pass in DATE parameters rather than passing in strings and letting Oracle implicitly convert the strings to dates using the session’s NLS_DATE_FORMAT. If you use date literals

    SELECT GETD(date '2012-06-27', date '2012-06-28') 
      FROM DUAL
    

    or convert the strings to dates explicitly using a TO_DATE

    SELECT GETD(to_date('27-JUN-12', 'DD-MON-RR'), to_date('28-JUN-12', 'DD-MON-RR')) 
      FROM DUAL
    

    then your call will work regardless of the client’s NLS_DATE_FORMAT.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function which creates a std::vector of iterators into another container:
I've got a question about date function on oracle. I have the following table
All, I have the following array and function, which will create a multidimensional array
have the following function on my collection : getFiltered: function (status, city) { return
I have the following function which in words should take user credentials and validate
I have created following function to fill field of a form page, there is
I have created the following function: public void DelegatedCall(Action<Object> delegatedMethod) And defined the following
I have created the following function to check the first value of the check
I have created a function (see below) that calculates a 7.5% sales tax. Now
I've created the following function backend: public string getImageURL() { return some text; }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.