75

I have an Oracle database on my network which I am able to connect to with Oracle SQL Developer, using hostname, port, username, password and the SID.

I need to connect another application (Quantum Gis), however it uses the Service Name instead of the SID.

Is there any way for me to determine the SERVICE_NAME of the database when I am connected in SQL Developer via the SID?

I do not have access to the server and have no local tnsnames.ora or similar.

6
  • 6
    Jakobsen:Just run the command Show parameter service_name Commented Mar 14, 2014 at 8:40
  • 2
    @GauravSoni AFAIK show parameter is a SQL/Plus command, and I'm not sure whether SQL Developer supports a SQL/Plus prompt. If it doesn't, the OP could use select * from v$parameter where name like '%service_name%' instead. Commented Mar 14, 2014 at 8:46
  • 1
    "Show parameter service_name;" returns error "Show parameters query failed". Commented Mar 14, 2014 at 8:48
  • 1
    "select value from v$parameter where name like '%service_name%';" returns ORA-00942: table or view does not exist Commented Mar 14, 2014 at 8:48
  • @AndersJakobsen:you dint have access to the data dictionary views ,ask your DBA to give access or send you the service name .And may be sql developer support the sqlplus commands ,as toad also support that F5 is the command in toad to run such commands. Commented Mar 14, 2014 at 8:52

8 Answers 8

92

Found here, no DBA : Checking oracle sid and database name

select * from global_name;
2
  • Many thanks, this one worked for me from Oracle SQL Developer. Commented Oct 20, 2016 at 22:17
  • 6
    GLOBAL_NAME gets you the global database name, which is not the same as the Service Name. (Although in some instances they could happen to be have the same value.) Commented Jul 13, 2020 at 15:24
51

Connect to the server as "system" using SID. Execute this query:

select value from v$parameter where name like '%service_name%';

It worked for me.

2
  • 2
    for anyone who need some help please note that the url needs the sid and not the service name. The full service name didn't work for me: jdbc:oracle:thin:@localhost:1521:orcl.athens.intrasoft-intl.private while this worked: jdbc:oracle:thin:@localhost:1521:orcl Commented Oct 6, 2015 at 15:27
  • 5
    @GeorgePligor: Please note the difference: jdbc:oracle:thin:@HOST:PORT:SID but jdbc:oracle:thin:@HOST:PORT/SERVICE Replace the uppercase words by the correct values. Please note the difference between the two strings: in the sid string the name of the sid ist separated by a : from the preceding string, in the service string the name is separated by a / from the preceding string
    – miracle173
    Commented May 10, 2017 at 16:07
29

Overview of the services used by all sessions provides the distionary view v$session(or gv$session for RAC databases) in the column SERVICE_NAME.

To limit the information to the connected session use the SID from the view V$MYSTAT:

select SERVICE_NAME from gv$session where sid in (
select sid from V$MYSTAT)

If the name is SYS$USERS the session is connected to a default service, i.e. in the connection string no explicit service_name was specified.

To see what services are available in the database use following queries:

select name from V$SERVICES;
select name from V$ACTIVE_SERVICES;
4
  • 2
    This just says SYS$USERS for me when I'm on the machine using SQL*Plus directly.
    – jpmc26
    Commented Nov 19, 2018 at 17:26
  • @jpmc26 SYS$USERS is the default service for user sessions that are not associated with services Commented Nov 19, 2018 at 18:26
  • I gathered, but the fact it doesn't work when running on the same machine makes this answer much less useful than others.
    – jpmc26
    Commented Nov 19, 2018 at 18:30
  • 1
    @jpmc26 extended the answer thaks to your suggestion. It is important to distinct the connected service and the available services. Commented Nov 19, 2018 at 18:45
16

Thanks to this thread (https://community.oracle.com/thread/473276)

select sys_context('userenv','service_name') from dual;

It can be executed with a regular user account, no need for sysdba rights

2
  • 13
    All it returns is SYS$USERS. I did eventually get in contact with the DBA, so this is no longer an issue Commented Mar 9, 2015 at 14:08
  • 1
    This actually did return the current Service_name as defined in the TNSNames for me. Have an upvote.
    – Marco
    Commented Oct 1, 2015 at 9:07
13

Check the service name of a database by

sql> show parameter service;

1
  • 4
    SHOW PARAMETERS; for everything.
    – akki
    Commented Jul 26, 2016 at 12:23
4

Connect to the database with the "system" user, and execute the following command:

show parameter service_name 
-1

TO FIND ORACLE_SID USE $. oraenv

-5

With SQL Developer you should also find it without writing any query. Right click on your Connection/Propriety.

You should see the name on the left under something like "connection details" and should look like "Connectionname@servicename", or on the right, under the connection's details.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.