Language: PL/SQL Highlight Mode: PLSQL Last Modified: March 03rd, 2009
CREATEORREPLACEFUNCTION fday_ofmonth(value_in DATE)RETURNDATEIS
vMo VARCHAR2(2);
vYr VARCHAR2(4);BEGIN
vMo :=TO_CHAR(value_in,'MM');
vYr :=TO_CHAR(value_in,'YYYY');RETURNTO_DATE(vMo ||'-01-'|| vYr,'MM-DD-YYYY');EXCEPTIONWHENOTHERSTHENRETURNTO_DATE('01-01-1900','MM-DD-YYYY');END fday_ofmonth;//*
Stuart S. sent in this comment and code:
It seems to me that there is no need to create a
function for this and string manipulation is a
somewhat inefficient method of doing this. The exact
same result can be obtained by simply truncating the
date to the month, without requiring a function to be
created:
*/TRUNC(<date>,'MM')SELECTTRUNC(datecol1,'MM')FROM t;SELECTTRUNC(SYSDATE,'MM')FROM dual;