
set define '^'
set verify off
set termout on

define ORDSSCHEMA   = '^1'

-- USING DBMS_SYS_SQL to prevent create job bugs when changing schemas
declare
  l_uid number;
  l_exec_result integer;
  l_sql varchar2(1000) := 'BEGIN
  SYS.DBMS_SCHEDULER.CREATE_JOB (
     job_name           =>  ''CLEAN_OLD_ORDS_SESSIONS'',
     job_type           =>  ''STORED_PROCEDURE'',
     job_action         =>  ''ORDS_INTERNAL.CLEAN_OLD_SESSIONS'',
     repeat_interval    =>  ''FREQ=HOURLY;INTERVAL=1'',
     comments           =>  ''ORDS SESSION CLEANUP'');
 SYS.DBMS_SCHEDULER.ENABLE (''CLEAN_OLD_ORDS_SESSIONS'');
END;
  ';
  l_stmt_cursor integer;
begin
     select user_id into l_uid from all_users where username like '^ORDSSCHEMA';
     l_stmt_cursor := sys.dbms_sys_sql.open_cursor();
     sys.dbms_sys_sql.parse_as_user(l_stmt_cursor, l_sql, dbms_sql.native, l_uid);
     l_exec_result := sys.dbms_sys_sql.execute(l_stmt_cursor);
     sys.dbms_sys_sql.close_cursor(l_stmt_cursor);
end;
/


