In Node.js, use the OracleDB library to execute Oracle database stored procedures: Install the OracleDB library. Create a database connection. Define the stored procedure name and parameters. Execute the stored procedure. Close the database connection.
In Node.js, you can use the OracleDB library to execute Oracle database stored procedures.
<code>npm install oracledb</code>
<code class="javascript">const oracledb = require('oracledb'); async function createConnection() { return oracledb.getConnection(connectionParams); }</code>
<code class="javascript">const procedureName = 'MY_PROCEDURE'; const parameters = { input: oracledb.NUMBER, output: oracledb.OUT };</code>
<code class="javascript">async function executeProcedure(connection) { const result = await connection.execute( procedureName, parameters, { autoCommit: true } ); return result.outBinds; }</code>
<code class="javascript">async function closeConnection(connection) { await connection.close(); }</code>
<code class="javascript">const connectionParams = { user: 'username', password: 'password', connectString: 'host:port/databasename' }; createConnection() .then(connection => executeProcedure(connection)) .then(result => console.log(result)) .catch(err => console.error(err)) .finally(() => closeConnection(connection));</code>
The above is the detailed content of How to run oracle database stored procedure in nodejs. For more information, please follow other related articles on the PHP Chinese website!