If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Last_day() function not working in db2 5.6 version

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-15-09, 21:55
sekhar.gajjala sekhar.gajjala is offline
Registered User
 
Join Date: Nov 2009
Posts: 4
Last_day() function not working in db2 5.6 version

HI,

IN a select query when i used last_day() function it is showing an error that it is not an user defined function, but when i used the same function in mainframe udb it is working fine.

Please let me know whether ibm has not provided this function in other db2 forms as AIX etc...

Thanks
Somasekhar Gajjala.
Reply With Quote
  #2 (permalink)  
Old 11-15-09, 23:18
sawangupta sawangupta is offline
Registered User
 
Join Date: Nov 2009
Location: Bangalore
Posts: 25
You can refer to the example from this blog

LAST_DAY, FIRST_DAY in DB2 | db2ude

Regards,
Sawan Gupta
Reply With Quote
  #3 (permalink)  
Old 11-15-09, 23:26
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
LAST_DAY supported on DB2 9.7 for LUW, DB2 for iSeries Version 5 Release 4 or later and DB2 for z/OS Version 7 or later.

But, DB2 5.6 for AIX is very old version.

Last edited by tonkuma; 11-15-09 at 23:58.
Reply With Quote
  #4 (permalink)  
Old 11-15-09, 23:41
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You could easily write your own function.

This is not a function, but will give you a hint on now to calculate it:

select date(substr(current_date, 1, 8)||'01') + 1 month - 1 day from sysibm.sysdummy1

Obviously, current_date in the above example would be replaced with the date for which you want to calculate the last day of the month.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #5 (permalink)  
Old 11-15-09, 23:54
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
You can refer to the example from this blog

LAST_DAY, FIRST_DAY in DB2 | db2ude
FIRST_DAY in the blog:
FIRST_DAY(SYSDATE) ==> values (current date - day(current date + 1 month) days) + 1 DAY
looks wrong.

For example, replace current date with DATE('2009-01-31') result:
Code:
------------------------------ Commands Entered ------------------------------
values (DATE('2009-01-31') - day(DATE('2009-01-31') + 1 month) days) + 1 DAY;
------------------------------------------------------------------------------

1         
----------
2009-01-04

  1 record(s) selected.
Please try this:
Code:
------------------------------ Commands Entered ------------------------------
SELECT date_
     , date_ - (DAY(date_) - 1) DAYS AS first_day
  FROM (VALUES current_date, DATE('2009-01-31') ) q(date_);
------------------------------------------------------------------------------

DATE_      FIRST_DAY 
---------- ----------
2009-11-16 2009-11-01
2009-01-31 2009-01-01

  2 record(s) selected.
Reply With Quote
  #6 (permalink)  
Old 11-17-09, 03:57
sekhar.gajjala sekhar.gajjala is offline
Registered User
 
Join Date: Nov 2009
Posts: 4
Quote:
Originally Posted by tonkuma View Post
LAST_DAY supported on DB2 9.7 for LUW, DB2 for iSeries Version 5 Release 4 or later and DB2 for z/OS Version 7 or later.

But, DB2 5.6 for AIX is very old version.

Sorry i mentioned version as 5.6 by mistake, actually i am using the db2 client 9.5.4
Reply With Quote
  #7 (permalink)  
Old 11-17-09, 03:59
sekhar.gajjala sekhar.gajjala is offline
Registered User
 
Join Date: Nov 2009
Posts: 4
Thanks for your replies,
we can write our own user defined functions for this, but i wanted to know that is this function is not provided by IBM or is there any problem with my client

Thanks
Somasekhar Gajjala.
Reply With Quote
  #8 (permalink)  
Old 11-17-09, 10:10
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Question

Quote:
Originally Posted by sekhar.gajjala View Post
Thanks for your replies,
we can write our own user defined functions for this, but i wanted to know that is this function is not provided by IBM or is there any problem with my client

Thanks
Somasekhar Gajjala.
What is yours query ?

Lenny
Reply With Quote
  #9 (permalink)  
Old 11-17-09, 11:09
sekhar.gajjala sekhar.gajjala is offline
Registered User
 
Join Date: Nov 2009
Posts: 4
The following is the error which i am getting

AIX-DEV ==>db2 "select last_day(hist_eff_dt) from dsnt.dws_geo_regions fetch first row only"
SQL0440N No authorized routine named "LAST_DAY" of type "FUNCTION" having
compatible arguments was found. SQLSTATE=42884

Thanks,
Somasekhar Gajjala.
Reply With Quote
  #10 (permalink)  
Old 11-17-09, 11:13
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by sekhar.gajjala View Post
Sorry i mentioned version as 5.6 by mistake, actually i am using the db2 client 9.5.4
What version is your database server? The function does not exist in the client.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #11 (permalink)  
Old 11-17-09, 11:16
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by sekhar.gajjala View Post
The following is the error which i am getting

AIX-DEV ==>db2 "select last_day(hist_eff_dt) from dsnt.dws_geo_regions fetch first row only"
SQL0440N No authorized routine named "LAST_DAY" of type "FUNCTION" having
compatible arguments was found. SQLSTATE=42884

Thanks,
Somasekhar Gajjala.
Make sure that your DBA updated the database after installing the last fixpack (the db update is done after the instance is updated). The database update typically adds SP and functions that are newly available in the latest releases. Please refer to fixpack install instructions for more info.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On