| |
|
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.
|
 |

11-15-09, 21:55
|
|
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.
|
|

11-15-09, 23:18
|
|
Registered User
|
|
Join Date: Nov 2009
Location: Bangalore
Posts: 25
|
|
|
|

11-15-09, 23:26
|
|
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.
|

11-15-09, 23:41
|
|
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
|
|

11-15-09, 23:54
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 2,193
|
|
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.
|
|

11-17-09, 03:57
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 4
|
|
Quote:
Originally Posted by tonkuma
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
|
|

11-17-09, 03:59
|
|
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.
|
|

11-17-09, 10:10
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 886
|
|
Quote:
Originally Posted by sekhar.gajjala
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
|
|

11-17-09, 11:09
|
|
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.
|
|

11-17-09, 11:13
|
|
Registered User
|
|
Join Date: May 2003
Location: USA
Posts: 5,196
|
|
Quote:
Originally Posted by sekhar.gajjala
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
|
|

11-17-09, 11:16
|
|
Registered User
|
|
Join Date: May 2003
Location: USA
Posts: 5,196
|
|
Quote:
Originally Posted by sekhar.gajjala
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
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|