简体   繁体   中英

Incrementing a field value over time in Oracle 12c

I am fairly new to databases and DBMS. I have a table in which there are multiples Integer fields. Number(3,0)

Is there a way to increment (+1) each ones of those fields over time with PL/SQL (automatic)?

For example, I have the field TEST(Number(3,0)) in my table and I want its value to increment by one for every hour that passes.

Thanks!

It's for a little game, I want every user to get one extra coin in their accounts for every day/hour that passes

You could create job to do it:

DBMS_SCHEDULER.create_job (
    job_name        => 'give_gold',
    job_type        => 'PLSQL_BLOCK',
    job_action      => 'BEGIN UPDATE tab_name SET gold_val = gold_val+1; END;',
    start_date      => SYSTIMESTAMP,
    repeat_interval => 'freq=hourly; byminute=0',
    end_date        => NULL,
    enabled         => TRUE,
    comments        => 'This job gives +1 gold every hour');

Of course you could fire stored procedure and make complex calculations. More info: DBMS_SCHEDULER

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM