0

How to get database name in oracle db node js


var oracledb = require('oracledb');
oracledb.getConnection(
    {
        user: 'c##root',
        password: 'root',
        connectString: 'localhost:1521/orcl'
    },
    function (err, connection) {

        if (err) {
            console.log('error while connect to OracleDB :' + err.stack);
            return;
        } else {
            console.log("Database connected")
            connection.execute("INSERT INTO person (name) VALUES  ( :NAME) ", ['DOE'], function (err, result) {
                if (err) {
                    console.error(err);
                    return;
                } else {
                    console.log("Value sucessfully added to database: " + "'database name here'")
                }
            });
        }
    });

I want to get name of the database when each time execute particular query.

MT0
  • 143,790
  • 11
  • 59
  • 117
Gopi Raj
  • 49
  • 3
  • What name are you referring to? Do you want `orcl` to be returned in this case (assuming that is the database SID)? Or do you want the schema name `c##root`? Or something else? Why don't you want to use the connection object? – Justin Cave Jul 06 '16 at 11:52
  • yes i want to get SID (orcl) using connection object. – Gopi Raj Jul 06 '16 at 19:44

1 Answers1

0

See How to find Oracle Service Name

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

PS in the given code, orcl is a service name, not a SID.

Community
  • 1
  • 1
Christopher Jones
  • 9,449
  • 3
  • 24
  • 48