PROMPT Creating user '&&1' with password '&&2'
SET ECHO OFF

whenever sqlerror exit failure;
DECLARE
    ecode NUMBER;
BEGIN
	EXECUTE IMMEDIATE 'DROP USER &&1 CASCADE';
EXCEPTION
    WHEN OTHERS THEN
        ecode := SQLCODE;
        IF ecode = -01918 THEN
            NULL;  -- User does not exist yet
        ELSIF ecode = -01940 THEN
            -- User is nog connected, killen maar....
            declare
               str     varchar2(100);
            begin
                for SES in (select sid,serial# from v$session
                       where username=UPPER('&&1')) loop
                       str := 'alter system kill session '||chr(39)||SES.sid||','||SES.serial#||chr(39);
                       execute immediate str;
                end loop;
                -- Tweede poging
                EXECUTE IMMEDIATE 'DROP USER &&1 CASCADE';
            end;

        ELSE
            RAISE; -- Overige fouten
        END IF;
END;
/

create user &&1 identified by &&2
    default tablespace fclt_data
    quota unlimited on fclt_data;

SET SERVEROUTPUT ON SIZE UNLIMITED;

grant connect, resource, create view to &&1;

exit