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

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Samrat.

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

Last updated: May 21, 2020 - 9:49 am UTC

Version: 12c

Viewed 1000+ 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 A.prod_id=B.prod'id;

and Chris 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;

C1   
   42 

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

C1   
   42 


Set the current_schema to the other schema:

drop synonym t ;

alter session set current_schema = other_user;

select * from t;

C1   
   42 


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?

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.