Escolar Documentos
Profissional Documentos
Cultura Documentos
SQLCODE
connect / as sysdba
set feedback off
spool oradbusr.log
set serverout on
set termout on
--set echo on;
/*---------------------------------------------------------------------------------*/
/* oradbusr.sql creates the Oracle Default Users for Operating
*/
/* system based DB authentication
*/
/*
*/
/* usage:
*/
/* UNIX: sqlplus /NOLOG @oradbusr.sql SCHEMAOWNER UNIX SAP_SID x
*/
/* NT: sqlplus /nolog @oradbusr.sql SCHEMAOWNER NT COMPUTER|DOMAIN SAP_SID
*/
/*
*/
/* The SCHEMAOWNER is either SAPR3 or has to start with SAP
*/
/* followed by the three digit schema id (example: SAPPRD).
*/
/* Specify DOMAIN, if you use Oracle 8.1.5 or higher
*/
/* On NT the Userdomain (DOMAIN) or Computername (COMPUTER)
*/
/* must be specified depending on wether you are using a domain or
*/
/* a local account.
*/
/* On Unix x is a dummy paramter and may e. g. be set to X
*/
/*---------------------------------------------------------------------------------*/
VARIABLE
VARIABLE
VARIABLE
VARIABLE
VARIABLE
VARIABLE
VARIABLE
VARIABLE
VARIABLE
VARIABLE
VARIABLE
VARIABLE
VARIABLE
VARIABLE
sPrefix varchar2(100)
sSchemaId varchar2(100);
sSapSid varchar2(100);
sVersion varchar2(100);
sDomain varchar2(100);
sR3user varchar2(100);
sSvcuser varchar2(100);
bONNT
number;
bSCHEMA number;
sSchema varchar2(100);
cur number;
r number;
stmt varchar2(200);
errtxt1 varchar2(200);
begin
declare
emergency EXCEPTION;
begin
if length('&&1') = 5 then
if substr(upper('&&1'),1,5) = 'SAPR3' then
:bSCHEMA := 0;
:sSchema := 'SAPR3';
if upper('&&2') = 'NT' then
:bONNT := 1;
else
:bONNT := 0;
end if;
if :bONNT = 1 then
:sDomain := upper('&&3');
:sSapSid := upper('&&4');
else
:sSapSid := upper('&&3');
end if;
else
dbms_output.put_line('-');
dbms_output.put_line('-');
dbms_output.put_line('--------------------------------------------------------------------');
dbms_output.put_line('not supported:');
dbms_output.put_line('Schemaowner has to be SAPR3 or SAP<SID> wh
ere <SID>');
dbms_output.put_line('has to be a three digit Identifier startin
g with a character');
dbms_output.put_line('--------------------------------------------------------------------');
dbms_output.put_line('-');
dbms_output.put_line('-');
raise emergency;
end if;
else
:bSCHEMA := 1;
:sSchema := upper('&&1');
if upper('&&2') = 'NT' then
:bONNT := 1;
else
:bONNT := 0;
end if;
if :bONNT = 1 then
:sDomain := upper('&&3');
:sSapSid := upper('&&4');
else
:sSapSid := upper('&&3');
end if;
end if;
end;
end;
/
set termout on
begin
declare
sPrefix varchar2(100);
nSchemaLen number;
begin
select version into :sVersion from v$instance;
select value into sPrefix from v$parameter where name='os_authent_prefix';
if :bSCHEMA = 1 then
:sSchemaId := substr(:sSchema,4,3);
else
:sSchemaId := 'R3';
end if;
sPrefix := upper(sPrefix);
if :bONNT = 1 then
if :sVersion > '8.1.0.0.0' then
:sR3user := sPrefix || :sDomain
:sSvcuser := sPrefix ||
Sid;
else
:sR3user := sPrefix || :sSapSid
:sSvcuser := sPrefix ||
end if;
else
:sR3user := sPrefix || :sSapSid
end if;
'||:sVersion);
'||sPrefix);
'||:sSchemaId);
'||:sSchema);
'||:sR3user);
'||:sSvcuser);
end;
/* grant privileges to schema owner
*/
statement := 'grant connect, resource, select_catalog_role, unlimited ta
blespace to ' || :sSchema;
dbms_sql.parse(c, statement, DBMS_SQL.NATIVE);
r := dbms_sql.execute(c);
/*--- alter user system and sys --- */
/* assign temporary tablespace to system
*/
begin
s := 'system';
statement := 'alter user ' || s || ' temporary tablespace psaptemp';
dbms_sql.parse(c, statement, DBMS_SQL.NATIVE);
r := dbms_sql.execute(c);
exception
when others then
dbms_output.put_line('unable to assign temporary tablespace psaptemp
to user: '||s);
RAISE;
end;
/* assign temporary tablespace to sys
*/
begin
s := 'sys';
statement := 'alter user ' || s || ' temporary tablespace psaptemp';
dbms_sql.parse(c, statement, DBMS_SQL.NATIVE);
r := dbms_sql.execute(c);
exception
when others then
dbms_output.put_line('unable to assign temporary tablespace psaptemp
to user: '||s);
RAISE;
end;
/*--- NT only: create SAP Service OPS$ user --- */
begin
if :bONNT = 1 then
s := :sSvcuser;
c := dbms_sql.open_cursor;
dbms_sql.parse(c, 'Create user "' || s || '" identified external
ly', DBMS_SQL.NATIVE);
r := dbms_sql.execute(c);
dbms_sql.close_cursor(c);
end if;
EXCEPTION
when others then
dbms_output.put_line('unable to create user: '||
s);
RAISE;
end;
/*--- Create SAPDBA role ---*/
begin
c := dbms_sql.open_cursor;
dbms_sql.parse(c, 'create role sapdba', DBMS_SQL.NATIVE);
r := dbms_sql.execute(c);
dbms_sql.close_cursor(c);
EXCEPTION
when others then
if sqlcode = -1921 then
s := 'dummy';
else
dbms_output.put_line('cannot create SAPDBA role: ');
RAISE;
end if;
end;
/*---
c := dbms_sql.open_cursor;
dbms_sql.parse(c, 'create synonym "'||:sSvcuser|| '".sapuser fo
r "' || :sR3user || '".SAPUSER',
DBMS_SQL.NATIVE);
r := dbms_sql.execute(c);
dbms_sql.close_cursor(c);
end if;
EXCEPTION
when others then
dbms_output.put_line('unable to create public synonym SAPUSER
');
RAISE;
end;
end;
end;
/
set echo off
set termout off
set feedback off
set serverout on
spool cocon.sql
begin
DECLARE
sHelp varchar2(200);
begin
dbms_output.put_line('connect ' || :sR3user || '/temp');
end;
end;
/
spool off
set termout on
WHENEVER OSERROR CONTINUE
@cocon.sql
WHENEVER OSERROR EXIT FAILURE
begin
DECLARE
c number;
r number;
begin
if :bONNT = 1 then
c := dbms_sql.open_cursor();
dbms_sql.parse(c, 'grant select, update, insert on sapuser to "' || :sSvcu
ser || '"', DBMS_SQL.NATIVE);
r := dbms_sql.execute(c);
dbms_sql.close_cursor(c);
end if;
EXCEPTION
when others then
dbms_output.put_line('unable to grant rights on sapuser');
RAISE;
end;
end;
/
WHENEVER OSERROR CONTINUE
connect / as sysdba
WHENEVER OSERROR EXIT FAILURE
begin
DECLARE
c number;
r number;
begin
c := dbms_sql.open_cursor();
dbms_sql.parse(c, 'alter user "' || :sR3user || '" identified externally',
DBMS_SQL.NATIVE);
r := dbms_sql.execute(c);
dbms_sql.close_cursor(c);
EXCEPTION
when others then
dbms_output.put_line('unable to grant rights on sapuser');
RAISE;
end;
end;
/
EXIT SUCCESS