0

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.

신동평
  • 119
  • 2
  • 11
  • do you refer to starting of the database, right after it is launched? – mikcutu Dec 15 '17 at 09:01
  • I did not understand your comment correctly, but no refer anything, and just execute sql query with startingup database. and thank you for interest in my question. I resolved my question. – 신동평 Dec 18 '17 at 04:49

2 Answers2

0

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?

mikcutu
  • 1,013
  • 2
  • 17
  • 34
0

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.

Kaushik Nayak
  • 30,772
  • 5
  • 32
  • 45