Jump to content

Hi am trying to convert some birth dates from one table to another as age groups

to be more spesific i got one table "xsales_customers"Capture.PNG.8806280b2704ddf9235891da5ec5589a.PNG

 

and i want from that table to transfer and modify the data from the column birth_date to another table named customers as agegroups ie under 35, above 70 etc..

here is what i have done so far

CREATE OR REPLACE PROCEDURE get_age_group AS
BEGIN
FOR omada27 IN (SELECT id FROM CUSTOMERS)
LOOP
UPDATE CUSTOMERS
SET Agegroup = TRUNC(MONTHS_BETWEEN(SYSDATE, BIRTH_DATE))/12
 SUM(CASE WHEN agegroup< 18 THEN 1 ELSE 0 END) AS  [Under 18],
 SUM(CASE WHEN agegroup BETWEEN 18 AND 24 THEN 1 ELSE 0 END) AS [18-24],
SUM(CASE WHEN agegroup BETWEEN 25 AND 34 THEN 1 ELSE 0 END) AS [25-34]
WHERE id = CUSTOMERS_ID;
END LOOP;
END get_age_group;

it has a very limited success. it only works without the sums and then only if i add birth_date column to the customers table

any help would be very helpfull

(FYI the data aren't real)

 

 

Link to comment
https://linustechtips.com/topic/1018556-plsql-transfer-modify-data/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×