1

How to find the schema(user) name from database using a select statement or are there any built in functions available?

I am using the following package for compiling all invalid objects in my schema, so instead of hard coding schema name, I would like to use a select statement or function which returns schema name.

DBMS_UTILITY.compile_schema('SCOTT');

Thanks

Jacob
  • 14,463
  • 65
  • 207
  • 320

2 Answers2

2

I guess, the USER system variable would correspond to what you need, if "my schema" corresponds to "my user", what it usually does:

declare
  u varchar2(100);
begin
  select user into u from dual;
  DBMS_UTILITY.compile_schema(u);
end;

Or without a PL/SQL block

DBMS_UTILITY.compile_schema(user);
Community
  • 1
  • 1
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • No need for a PL/SQL block: `DBMS_UTILITY.compile_schema(user);` should work just fine –  Jul 24 '12 at 10:55
0

Schemas in Oracle DB are users, so if you want to take all schemas you need to use the dba_users table:

SELECT USERNAME
FROM DBA_USERS;

Remember that this is a system table so appropriate user granting is necessary.

If you need the current user, you can user the USER_USERS view. See here for further information.

Hope this helps!

Vincenzo Maggio
  • 3,787
  • 26
  • 42