I wonder how the TNS identifier can be used within a SQL script. In this example
$ sqlplus MY_USER/pswd@TNSID @script.sql par1 par2
I'd like to get TNSID as a string in order to use it from script.sql
but I have no idea where to find it.
The goal is to reconnect as a different user on the same instance.
Best Answer
You can define the environment (TNS_ALIAS) before launching sqlplus.
First let's create two users (a and b)
On Linux set the TWO_TASK environment variable like this:
You will see from the sqlplus prompt the user you are logged in as.
As a side note, defining your connection with a TNS_ALIAS inside a sql-script is going to bite you hard at one point when you realize that your TNS_ALIAS is pointing to a PROD database instead of TEST database.
TWO_TASK equivalent on Windows is LOCAL ala
PS>$env:LOCAL = "XEPDB1"