DB2 - procedure to display the age in years & months

Bandi
Posted by Bandi under Others category on | Points: 40 | Views : 581


CREATE PROCEDURE DOB_PROC (DOB DATE, OUT P_RES VARCHAR (300))
SPECIFIC DOB1
BEGIN
DECLARE V_DOB DATE;
DECLARE V_YEARS INT DEFAULT 0;
DECLARE V_MONTHS INT DEFAULT 0;

SET V_YEARS = MONTHS_BETWEEN (CURRENT_DATE, DOB)/12;

SET V_MONTHS = MOD (MONTHS_BETWEEN (CURRENT_DATE, DOB) ,12);

SET P_RES = 'YOU ARE '||V_YEARS||'YEARS AND ' || V_MONTHS || 'MONTHS OLD';
END@

-- call the stored procedure as follows:
CALL DOB_PROC ('1988-10-27', ?)

Comments or Responses

Login to post response