Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
col db new_value sid noprint
accept fr_usr prompt " From user: "
accept to_usr prompt "To user (''=same): "
col fr_usr new_value fr_usr noprint
col to_usr new_value to_usr noprint
col cr_type new_value cr_typ noprint
select UPPER('&&fr_usr') fr_usr
, UPPER(NVL('&&to_usr','&&fr_usr')) to_usr
, name db from v$database;
select decode('&&to_usr','&&fr_usr'
,'Migrate_&&fr_usr','Create_&&to_usr') cr_type from dual;
set pages 0 lin 80 feed off ver off recsep off trims on
set term on
col sq noprint
spo /tmp/&&sid._&&cr_typ..sql
Select username||to_char(100+rownum) sq,
'Create User '||decode('&&to_usr','&&fr_usr'
,u.username||' identified by values '||chr(39)||password||chr(39)
,'&&to_usr identified by &&to_usr'||to_char(sysdate,'DD'))||chr(10)
||' Default tablespace '||default_tablespace||chr(10)
||' Temporary tablespace '||temporary_tablespace||';'||chr(10)
from dba_users u
where username = '&&fr_usr'
UNION
Select username||to_char(200+rownum) sq, 'Alter User &&to_usr'
||' quota '||decode(max_bytes,-1,'UNLIMITED',max_bytes/1024||'K')
||' ON '||tablespace_name||';'||chr(10)
from dba_ts_quotas q
where username = '&&fr_usr'
order by 1
/
spo off
prompt Script is at: /tmp/&&sid._&&cr_typ..sql
Enter value for cr_typ: 'Create User '||decode('&&to_usr','&&fr_usr'
SP2-0333: Illegal spool file name: "/tmp/Select username||to_char(100+rownum) sq,_ 'Create User '||d
SQL> ,u.username||' identified by values '||chr(39)||password||chr(39)
SP2-0734: unknown command beginning ",u.usernam..." - rest of line ignored.
SQL> ,'&&to_usr identified by &&to_usr'||to_char(sysdate,'DD'))||chr(10)
SP2-0734: unknown command beginning ",'&&to_usr..." - rest of line ignored.
SQL> ||' Default tablespace '||default_tablespace||chr(10)
SP2-0734: unknown command beginning "||' Def..." - rest of line ignored.
SQL> ||' Temporary tablespace '||temporary_tablespace||';'||chr(10)
SP2-0734: unknown command beginning "||' Tem..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SQL> from dba_users u
SP2-0734: unknown command beginning "from dba_u..." - rest of line ignored.
SQL> where username = '&&fr_usr'
SP2-0734: unknown command beginning "where user..." - rest of line ignored.
SQL> UNION
SP2-0042: unknown command "UNION" - rest of line ignored.
SQL> Select username||to_char(200+rownum) sq, 'Alter User &&to_usr'
2 ||' quota '||decode(max_bytes,-1,'UNLIMITED',max_bytes/1024||'K')
3 ||' ON '||tablespace_name||';'||chr(10)
4 from dba_ts_quotas q
5 where username = '&&fr_usr'
6 order by 1
7 /
Select username||to_char(200+rownum) sq, 'Alter User select decode('&&to_usr','&&fr_usr''
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
SQL> spo off
not spooling currently
SQL> prompt Script is at: /tmp/&&sid._&&cr_typ..sql
Script is at: /tmp/Select username||to_char(100+rownum) sq,_ 'Create User '||decode('&&to_usr','&&fr
SQL>
set pagesize 0
set linesize 200
set trimspool on
spool temp_clone_users.sql
select 'set feedback on'||chr(10)||'set echo on'||chr(10)||
'spool temp_clone_users.log'
from dual;
select 'REM ==== Creating User "'||username||'" ============================'||chr(10)||
'create user '||username||' identified by values '''||password||''''||chr(10)||
'default tablespace '||default_tablespace||chr(10)||
'temporary tablespace '||temporary_tablespace||chr(10)||
'quota unlimited on '||default_tablespace||chr(10)||
'/'||chr(10)||
'grant connect, resource to '||username||chr(10)||
'/'||chr(10)||
'grant create view to '||username||chr(10)||
'/'
from dba_users
where username not in ('SYS','SYSTEM','APEX_PUBLIC_USER','BI','CTXSYS','DBSNMP','EXFSYS','IX','MDDATA','MDSYS'
,'OE','OLAPSYS','ORACLE_OCM','ORDPLUGINS','ORDSYS','OUTLN','OWBSYS','PM','SCOTT'
,'SI_INFORMTN_SCHEMA','SPATIAL_CSW_ADMIN_USR','SPATIAL_WFS_ADMIN_USR','SYSMAN'
,'TMSYS','WMSYS','XDB')
order by username
/
select 'spool off'||chr(10)||'prompt wrote logfile: "temp_clone_users.log"' from dual;
prompt
prompt Wrote script 'temp_clone_users.sql'
prompt
SQL> @users_clone
set feedback on
set echo on
spool temp_clone_users.log
REM ==== Creating User "YADA4" ============================
create user YADA4 identified by values '12F8EACC8D03829E'
default tablespace DATA1
temporary tablespace TEMP
quota unlimited on DATA1
/
grant connect, resource to YADA4
/
grant create view to YADA4
/
REM ==== Creating User "YADA5" ============================
create user YADA5 identified by values 'C54F3C5E3601C239'
default tablespace DATA1
temporary tablespace TEMP
quota unlimited on DATA1
/
grant connect, resource to YADA5
/
grant create view to YADA5
/
spool off
prompt wrote logfile: "temp_clone_users.log"
Wrote script 'temp_clone_users.sql'
SQL> @temp_clone_users
SQL> spool temp_clone_users.log
SQL>
SQL> REM ==== Creating User "YADA4" ============================
SQL> create user YADA4 identified by values '12F8EACC8D03829E'
2 default tablespace DATA1
3 temporary tablespace TEMP
4 quota unlimited on DATA1
5 /
User created.
SQL> grant connect, resource to YADA4
2 /
Grant succeeded.
SQL> grant create view to YADA4
2 /
Grant succeeded.
SQL>
SQL> REM ==== Creating User "YADA5" ============================
SQL> create user YADA5 identified by values 'C54F3C5E3601C239'
2 default tablespace DATA1
3 temporary tablespace TEMP
4 quota unlimited on DATA1
5 /
User created.
SQL> grant connect, resource to YADA5
2 /
Grant succeeded.
SQL> grant create view to YADA5
2 /
Grant succeeded.
SQL>
SQL> spool off
SQL> prompt wrote logfile: "temp_clone_users.log"
wrote logfile: "temp_clone_users.log"
SQL>
------------------------------------------------------------------
def ORATMP=/tmp
cl breaks col
col db new_value sid
select name db from v$database;
set echo off head off pages 0 lin 120 timing off feed off
set termout off verify off trims on recsep off
spool &&ORATMP/&sid._migrate_grants.sql
set termout off
col sq noprint
select 'Grant '||granted_role||' to '||grantee
||decode(admin_option,'YES',' With ADMIN OPTION;',';')||chr(10)
from (
select username
from dba_users u
where lock_date is null
) x, dba_role_privs r
where r.grantee = x.username
and r.grantee not in
('ANONYMOUS','CTXSYS','DBSNMP','MDSYS','OLAPSYS','ORDPLUGINS','ORDSYS'
,'SYS','SYSTEM','WKSYS','WKUSER01','WMSYS')
order by 1
/
select 'Grant '||privilege||' to '||grantee
||decode(admin_option,'YES',' With ADMIN OPTION;',';')||chr(10)
from (
select username
from dba_users u
where lock_date is null
) x, dba_sys_privs s
where s.grantee = x.username
and s.grantee not in
('ANONYMOUS','CTXSYS','DBSNMP','MDSYS','OLAPSYS','ORDPLUGINS','ORDSYS'
,'SYS','SYSTEM','WKSYS','WKUSER01','WMSYS')
order by 1
/
spool off
exit
-- --------------------------------------
-- db_su.sql : Become another user.
--
set term off
store set sqlplus_env rep
set pages 0 feed off ver off echo off term off
DEF user=&1
spo temp&1..sql
conn /
select 'alter user &user identified by values '''||password||''';'
from dba_users where username = UPPER('&user')
/
spo off
alter user &user identified by temp;
connect &user/temp
START temp&1..sql
@sqlplus_env
set term on
-- Set the following to the location (path) of db_su.sql:
def ORASQL=~/dba/scripts/sql
def ORATMP=/tmp
cl breaks col
col db new_value sid
select name db from v$database;
set echo off head off pages 0 lin 120 timing off feed off
set termout off verify off trims on recsep off
col sq noprint
spool &&ORATMP/&sid._migrate_user_grants.sql
select x.rn*10000+p.rn sq,
||'@&&ORASQL/db_su '||x.schema||chr(10),NULL)
decode(p.rn,1,'@&&ORASQL/db_su '||x.schema||chr(10),NULL)
||'Grant '||privilege||' on '||grantor||'.'||table_name
||' to '||grantee||';'||chr(10) sql
from (
select username schema, row_number() over(order by username) rn
from ( select username from dba_users u
where --lock_date is null and
u.username not in
('ANONYMOUS','CTXSYS','DBSNMP','MDSYS','OLAPSYS','ORDPLUGINS','ORDSYS'
,'SYS','SYSTEM','WKSYS','WKUSER01','WMSYS')
UNION select role from dba_roles )
) x
,(
select grantor, grantee, privilege, table_name
, row_number() over(partition by grantor order by table_name) rn
from dba_tab_privs ) p
where p.grantor=x.schema
order by p.grantor, p.table_name
/
spo off
set pagesize 0
set linesize 200
set trimspool on
set echo off
set feedback off
spool temp_clone_users_privs.sql
select 'set feedback on'||chr(10)||'set echo on'||chr(10)||
'spool temp_clone_users.log'
from dual;
col grantee noprint
break on grantee skip 1
select 'grant '||privilege||' to '||grantee||';'
,grantee
from (select grantee, privilege from dba_sys_privs
union
select grantee, granted_role from dba_role_privs)
,dba_users
where username not in ('SYS','SYSTEM','APEX_PUBLIC_USER','BI','CTXSYS','DBSNMP','EXFSYS','IX','MDDATA','MDSYS'
,'OE','OLAPSYS','ORACLE_OCM','ORDPLUGINS','ORDSYS','OUTLN','OWBSYS','PM','SCOTT'
,'SI_INFORMTN_SCHEMA','SPATIAL_CSW_ADMIN_USR','SPATIAL_WFS_ADMIN_USR','SYSMAN'
,'TMSYS','WMSYS','XDB')
and username = grantee
order by username
/
set termout off
select 'spool off'||chr(10)||'prompt wrote logfile: "temp_clone_users_privs.log"' from dual;
spool off
set termout on
prompt
prompt Wrote script 'temp_clone_users_privs.sql'
prompt
SQL> @users_privs_clone
set feedback on
set echo on
spool temp_clone_users.log
grant CONNECT to YADA4;
grant CREATE VIEW to YADA4;
grant RESOURCE to YADA4;
grant UNLIMITED TABLESPACE to YADA4;
grant CONNECT to YADA5;
grant CREATE VIEW to YADA5;
grant RESOURCE to YADA5;
grant UNLIMITED TABLESPACE to YADA5;
Wrote script 'temp_clone_users_privs.sql'
ERROR:
ORA-12560: TNSrotocol adapter error
[Start] -> [Control Panel] -> [System] -> [Advanced] -> [Environment Variables] -> (system Variables frame) [New] -> (Variable Name) "ORACLE_HOME" -> (Variable Value) "<your specific Oracle Home, example: C:\Oracle\Ora8...whatever" -> [OK] -> [OK] -> [OK]
SQL PlusBTW, by what software and entries (exactly) are you attempting to connect from your remote client to the Oracle server?