PROMPT Requires 'GRANT ANALYZE ANY TO <tascha_schema>;'

CONN &&tascha_schema/&&tascha_password

SET SERVEROUTPUT ON

DECLARE
	L_task_id	NUMBER;
	L_sched_id	NUMBER;
BEGIN
	/* Allow to fail if task no already present */

	SELECT	task_id
	INTO	L_task_id
	FROM	tasks
	WHERE	procedure_name = 'gather_schema_stats'
	AND	ROWNUM = 1;

	dbms_output.put_line('task:'||L_task_id);

	/* Analyze schema on last sunday in month */

	tascha_pkg.schedule_task(I_task_id 	=> L_task_id
			,	I_title		=> 'PERFSTAT'
			,	I_hour 		=> '01'
			,	I_min 		=> '00'
			,	I_dow 		=> 'SUN'
			,	I_dow_last	=> TRUE
			,	O_sched_id 	=> L_sched_id);

	dbms_output.put_line('sched:'||L_sched_id);

	tascha_pkg.add_task_prm(L_sched_id,	'ownname',	'PERFSTAT');
	tascha_pkg.add_task_prm(L_sched_id,	'cascade',	'TRUE');

	COMMIT;
END;
/
