We have a legacy code which connectes to Oracle DB using SQLPLUS command:
sqlplus "$USERNAME/$PASSWORD@//$HOST:$PORT/$SERVICE_NAME"
Values of variables USERNAME, PASSWORD, HOST, PORT and SERVICE_NAME are configured using external properties file. This code works when we have the DB with the service name. In our case DB has default serice:
SYS_CONTEXT('USERENV','SERVICE_NAME')
-------------------------------------
SYS$USERS
DB has only the SID:
SYS_CONTEXT('USERENV','SID')
----------------------------
521
Is there any way to connect to Oracle DB using default service name? e.g.
sqlplus "$USERNAME/$PASSWORD@//$HOST:$PORT/SYS$USERS"
It fails with error: ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
WE also tried with SID as:
sqlplus "$USERNAME/$PASSWORD@//$HOST:$PORT/521"
It fails with error:
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
There is no scope to change code of this legacy app or change DB to add service names. Please let me know if there is any to resolve this issue.
You are mis-using sys_context to determine the correct values for SERVICE_NAME or SID. This is not what SYS_CONTEXT is reporting. The "sid" here is your session_id, not the database's system id. I'm not sure exactly what SYS.USERS represents in this context, but it is certainly NOT a service name by which you connect to a database. You should look at v$parameter:
Or better, just look at the output of 'lsnrctl status' to show you what the listener _does_ know.
I have never seen a listener serving SYS$USERS.