SET TIME ON

declare
v_proc varchar2(100);
v_sid number;
v_serial number;
v_paddr VARCHAR2 (255);
v_spid number;


err_num NUMBER;
err_msg VARCHAR2 (255);

begin
    select sid, serial#, paddr into v_sid, v_serial, v_paddr from v$session where sid = &1 and type='USER';
	
    select sid, serial# into v_sid, v_serial from v$session where sid = &1 and type='USER';
	select spid into v_spid from v$process where addr = v_paddr;
	dbms_monitor.session_trace_enable(session_id => v_sid, serial_num => v_serial, waits => true, binds => true);
	dbms_output.put_line('Traza habilitada '||TO_CHAR(SYSDATE,'DDMMYYYY HH24:MI:SS')||'. SID:'||v_sid||' - SERIAL:'||v_serial||' - SPID:'||v_spid);
	
exception
	when others then
		err_num := SQLCODE;
		err_msg := SQLERRM;

		dbms_output.put_line('Traza no activada. La sesión o el proceso no existen');
		dbms_output.put_line(substr('ERROR:' || ERR_NUM || '-' || ERR_MSG, 1, 255));
end;
/

undefine &1