column sid_serial format a10
column username format a20
column STATUS format a10
column event format a30
column OSUSER format a10
column machine format a30
column program format a20
column inst format 9

declare

type t_inst_id is table of number;
type t_sid_serial is table of varchar2(100);
type t_username is table of varchar2(100);
type t_status is table of varchar2(100);
type t_last_call_et is table of varchar2(100);
type t_sql_id is table of varchar2(100);
type t_event is table of varchar2(100);
type t_LOGON_TIME is table of varchar2(100);
type t_program is table of varchar2(100);

v_inst_id t_inst_id;
v_sid_serial t_sid_serial;
v_username t_username;
v_status t_status;
v_last_call_et t_last_call_et;
v_sql_id t_sql_id;
v_event t_event;
v_LOGON_TIME t_LOGON_TIME;
v_program t_program;

begin
for i in 1..&3 loop
select inst_id inst,sid||' '||serial# sid_serial,username,status,last_call_et,sql_id,event,to_char(logon_time,'ddmmyyyy hh24:mi:ss') LOGON_TIME,program
bulk collect into v_inst_id,v_sid_serial,v_username,v_status,v_last_call_et,v_sql_id,v_event,v_LOGON_TIME,v_program
from gv$session
where username like upper('%&1%') and event not like 'Streams%' and status='ACTIVE'
order by inst_id,last_call_et;

for j in 1..v_inst_id.count loop
dbms_output.put_line(v_inst_id(j)||' '||v_sid_serial(j)||' '||v_username(j)||' '||v_status(j)||' '||v_last_call_et(j)||' '||v_sql_id(j)||' '||v_event(j)||' '||v_LOGON_TIME(j)||' '||v_program(j));
end loop;

dbms_lock.sleep(&2);

end loop;
end;
/