Home > database >  How do you use the oracle stored procedure to calculate age and modify age
How do you use the oracle stored procedure to calculate age and modify age

Time:09-16

Known conditions table, the table of date of birth field create_data
The age field for age
Seek help from a great god

CodePudding user response:

This simple create_data - sysdate, that is, the number of days of birth, want to know, as/365,
SELECT create_data, date of birth (create_data - sysdate)/365 age FROM the table name,

CodePudding user response:

Said the calculation rules,

Is directly according to the years, or to a month, or the day?

CodePudding user response:

reference 1st floor AHUA1001 response:
this simple create_data - sysdate, is the number of days of birth, want to know, as/365,
SELECT create_data, date of birth (create_data - sysdate)/365 age FROM the table name,


Decreased the

CodePudding user response:

reference 1st floor AHUA1001 response:
this simple create_data - sysdate, is the number of days of birth, want to know, as/365,
SELECT create_data, date of birth (create_data - sysdate)/365 age FROM the table name,

This reality should be more complex, number of days all is not 365 days?

CodePudding user response:

You design apparently does not conform to the paradigm of the table, because you can calculate the age from birth, so your age field is dependent on reate_date, and both are the primary key, then violated the database of the third paradigm,
This case, the table data is inconsistent problems, age, if want to consider the problem of one full year of life, difficult to you to age to update this table all done once a day, especially under the condition of special data,
In oracle11 (as if, can't remember) increased, the concept of virtual columns and operation, age can be set to the virtual, virtual columns is calculated according to the virtual columns by formula, when creating a table is designed, but virtual columns cannot be update, can't insert the data when inserting data, can query, this simplifies application design personnel design,

CodePudding user response:

Don't want to do so, see between_month function, floor function

The update tablename set age=floor (between_month (sysdate - createdate)/12) where id=XXX;
  • Related