How to execute query when oracle starting up?

234 Views Asked by At

I have some question. I want to execute some SQL query when oracle starting up(initialization).

for instance, Linux, Windows, and etc. OS are enable to run program, when computer start up.

anyway, my purpose is executing some query in oracle 11g r1, when oracle starting up.

2

There are 2 best solutions below

1
On BEST ANSWER

You could use AFTER STARTUP Triggers.

create or replace trigger
   tr_startup_actions
after startup on database
begin

procedure_runing_query(p_arg1);
end;
/

Run the query you need to inside the procedure or within the block if you need it. But, you should decide a way to store the result of the query somewhere. storing it in a table would be better.

0
On

here is an example:

CREATE OR REPLACE TRIGGER 
   manage_service
after startup on database
DECLARE
   role VARCHAR(30);
BEGIN
   SELECT DATABASE_ROLE INTO role FROM V$DATABASE;
   IF role = 'PRIMARY' THEN
      DBMS_SERVICE.START_SERVICE('sales_rw');
   ELSE
      DBMS_SERVICE.START_SERVICE('sales_ro');
END IF;
END;

is this what you need?