node.js 查询oralce数据库数据
时间: 2023-11-24 07:50:44 浏览: 33
以下是使用node-oracledb查询Oracle数据库数据的示例代码:
```javascript
const oracledb = require('oracledb');
async function run() {
let connection;
try {
// 连接到Oracle数据库
connection = await oracledb.getConnection({
user: 'your_username',
password: 'your_password',
connectString: 'your_connection_string'
});
// 执行SQL查询
const result = await connection.execute(
`SELECT *
FROM your_table
WHERE your_condition = :your_value`,
[your_value]
);
console.log(result.rows); // 输出查询结果
} catch (err) {
console.error(err);
} finally {
if (connection) {
try {
// 关闭数据库连接
await connection.close();
} catch (err) {
console.error(err);
}
}
}
}
run();
```
在上面的代码中,我们首先使用`oracledb.getConnection()`方法连接到Oracle数据库。然后,我们使用`connection.execute()`方法执行SQL查询,并将查询结果存储在`result`变量中。最后,我们输出查询结果并关闭数据库连接。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)