This works:
undefine schema_display
col schema_display new_value schema_display
set termout off
select lower(sys_context('userenv', 'current_schema')) schema_display from dual
/
set termout on
set sqlprompt "&&schema_display.':'_USER'@'_CONNECT_IDENTIFIER > "
So:
USER@SID > alter session set current_schema="TEST";
Session altered.
USER@SID > -- run the above
TEST:USER@SID >
However, the prompt stays set to that value until another SET SQLPROMPT is performed. You need to put the code to switch schemas and create the schema_display variable in a script (like "switch_schema.sql"):
alter session set current_schema="&new_schema";
undefine schema_display
col schema_display new_value schema_display
set termout off
select lower(sys_context('userenv', 'current_schema')) schema_display from dual;
set termout on
set sqlprompt "&&schema_display.':'_USER'@'_CONNECT_IDENTIFIER > "
The &new_schema variable causes SQL*PLUS to prompt you for the schema you want to switch to.
USER@SID > @switch_schema
Enter value for new_schema: TEST
old 1: alter session set current_schema="&new_schema"
new 1: alter session set current_schema="TEST"
Session altered.
test:USER@SID >