set lines 300
set pages 30000
--SET TRIMOUT OFF
--SET TRIMS OFF
SET COLSEP '|'
SET VER OFF

begin
dbms_output.put_line('----------------------------------------------------------------------');
dbms_output.put_line('ID-IDSESION');
dbms_output.put_line('A-ACTIVE');
dbms_output.put_line('U-%ORA_USUARIO%');
dbms_output.put_line('M-%MACHINE%');
dbms_output.put_line('IP-%IP%');
dbms_output.put_line('T-%TEGNOLOGIA%');
dbms_output.put_line('P-%PROGRAMA%');
dbms_output.put_line('----------------------------------------------------------------------');
end;
/

--column ID format 999 word_wrapped
column OS_USUARIO format a20 word_wrapped
column ORA_USUARIO format a20 word_wrapped
column MAQUINA format a20 word_wrapped
column IP format a19 word_wrapped
column PROGRAMA format a20 word_wrapped
column MODULO format a20 HEADING MODULO word_wrapped
column TEGNOLOGIA format a4 word_wrapped
column HORA_INICIO format a8 HEADING HINICIO word_wrapped
column HORA_FIN format a8 HEADING HFIN word_wrapped
column ADMINDBA format a3 HEADING DBA word_wrapped
column SERVICIO format a20 word_wrapped

SET TERM OFF
DEFINE V_1 = ''
COLUMN VV_1 NOPRINT NEW_VALUE V_1
SELECT '&&1' VV_1 FROM dual;

DEFINE V_2 = ''
COLUMN VV_2 NOPRINT NEW_VALUE V_2
SELECT '&&2' VV_2 FROM dual;
SET TERM ON

SELECT ses.activo,srv.activo,ses_srv.activo,srv.servicio,ses.IDSESION ID,ses.ORA_USUARIO, ses.MAQUINA, ses.IP, ses.PROGRAMA, ses.TEGNOLOGIA, ses.HORA_INICIO, ses.HORA_FIN
FROM astsysadmin.t_mods_sesion ses
    ,astsysadmin.t_mods_servicios srv
    ,astsysadmin.t_mods_sesion_servicio ses_srv
WHERE ses_srv.idsesion = ses.idsesion
AND ses_srv.idservicio = srv.idservicio
AND 
--(
(UPPER('&V_1') = 'ALL') 
--OR (UPPER('&V_1') = 'ID' AND IDSESION = '&V_2')
--OR (UPPER('&V_1') = 'A' AND ACTIVO = UPPER('&V_2'))
--OR (UPPER('&V_1') = 'U' AND ORA_USUARIO LIKE UPPER('%&V_2%'))
--OR (UPPER('&V_1') = 'M' AND MAQUINA LIKE UPPER('%&V_2%'))
--OR (UPPER('&V_1') = 'IP' AND IP LIKE UPPER('%&V_2%'))
--OR (UPPER('&V_1') = 'T' AND TEGNOLOGIA LIKE UPPER('%&V_2%'))
--OR (UPPER('&V_1') = 'P' AND PROGRAMA LIKE UPPER('%&V_2%'))
--)
ORDER BY srv.servicio,ses.PROGRAMA,ses.MAQUINA;

UNDEFINE V_1
UNDEFINE V_2


