Skip to Main Content
  • Questions
  • Want to pass schema name as dynamically mode


Question and Answer

Chris Saxon

Thanks for the question, Samrat.

Asked: May 20, 2020 - 7:58 am UTC

Answered by: Chris Saxon - Last updated: May 21, 2020 - 9:49 am UTC

Category: PL/SQL - Version: 12c

Viewed 100+ times

You Asked

My question is over here that I just wann to pass 'Scott' schema name as dynamic,because schema name has changed every 2 month like 'scott.1' and ' scott.2' and so on.

Select prod_id,prod_name from product A,scott.product_details B where'id;

and we said...

There are a couple of things you could look into:

Use synonyms/views so you don't need to specify the schema:

grant dba to other_user 
  identified by other_user;
create table other_user.t (
  c1 int

insert into other_user.t values ( 42 );

select * from other_user.t;


create synonym t 
  for other_user.t;
select * from t;


Set the current_schema to the other schema:

drop synonym t ;

alter session set current_schema = other_user;

select * from t;


Though if you're using tables from different schemas (as implied by your example), you'll need to give the schema for your current user.

But... why do you need to change the schema name regularly?

More to Explore


The Oracle documentation contains a complete SQL reference.