Big data develops the sample code of Chinese age function
This article mainly introduces big data to develop the Chinese age function sample code, the article introduces in great detail, has a certain reference value, interested friends must read it!
Create or replace function CHINESEAGE (BirthDate in date, NowDate in date) return string is Result string (80);-- return value MonthCount number (4);-- month of birth DayCount number (6);-- remainder of the month (days) begin-- error if BirthDate > NowDate or BirthDate is null or NowDate is null Then Result: = 'unknown' if the birthday is greater than the current date Return (Result); end if;-get SELECT trunc (Mon), trunc ((Mon-trunc (Mon)) * 31) INTO MonthCount,DayCount FROM (SELECT months_between (NowDate, BirthDate) Mon FROM dual) V -- if you are more than 60 months old, your age will be # # years old if MonthCount > = 60 then Result: = to_char (trunc (MonthCount/12)) | | 'year';-- if you are 12-59 months old, your age will be # # years # / month elsif MonthCount > = 12 then Result: = to_char (trunc (MonthCount/12)) | | 'year' | | to_char (mod (MonthCount,12)) | | 'month' -if you are 1-11 months old, the age is displayed as # eptember # day elsif MonthCount > = 1 then Result: = to_char (MonthCount) | | 'month'; if DayCount > = 1 then Result: = Result | | to_char (DayCount) | | 'day'; end if -- if born 1 day-1 month, the age is displayed as # days elsif DayCount > = 1 then Result: = to_char (DayCount) | | 'day';-- if born less than 1 day, the age is displayed as 1 day else Result: ='1 day'; end if; return (Result); end The above is all the content of this article "big data develops the sample code of Chinese age function". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!