--list of users that can be locked
create table bkp_dwh.lock_users as (select username from dbA_users where oracle_maintained not in ('Y') 
and profile NOT IN ('ORA_PROTECTED_PROFILE','ORA_ADMIN_PROFILE','ORA_EXTAPP_PROFILE') 
and account_status = 'OPEN'
and default_tablespace not like 'SYS%'
and username NOT IN ('PDBSOFA') and username NOT LIKE 'ECB%');

--kill current sessions and lock the users for imp/exp
 set serveroutput on
 declare
    sqlStmt VARCHAR2(1000);
    sqlStmt2 VARCHAR2(1000);
    sqlStmt3 VARCHAR2(1000);
 BEGIN
   For y in (Select username from bkp_dwh.lock_users)
   loop
     For x in (SELECT SID,SERIAL#,TERMINAL FROM V$SESSION WHERE schemaname=y.username)
     loop
       sqlStmt  := 'ALTER SYSTEM DISCONNECT SESSION ''' ||X.SId ||',' ||X.Serial# ||''' IMMEDIATE';
       sqlStmt2 := 'ALTER SYSTEM KILL SESSION ''' ||X.SId ||',' ||X.Serial# ||''' IMMEDIATE';       
       dbms_output.put_line( sqlStmt);
       dbms_output.put_line( sqlStmt2);
       dbms_output.put_line( x.terminal);
       EXECUTE IMMEDIATE sqlStmt;
       EXECUTE IMMEDIATE sqlStmt2;
     End loop;
     sqlStmt3 := 'ALTER USER '||y.username||' ACCOUNT LOCK';
     dbms_output.put_line( sqlStmt3);
     EXECUTE IMMEDIATE sqlStmt3;
    END LOOP;
end;
/