Skip to content

Commit 17cc3f6

Browse files
committed
Mention PL/SQL named param syntax. See issue #420
1 parent 0a4ad41 commit 17cc3f6

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

doc/api.md

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5922,20 +5922,30 @@ a [`maxArraySize`](#executebindParams) property is also required
59225922
The [`results`](#executecallback) parameter of the `execute()`
59235923
callback contains an [`outBinds`](#execoutbinds) property with the
59245924
returned OUT and IN OUT bind values.
5925-
If [`bindParams`](#executebindParams) was passed as an array, then
5926-
`outBinds` is returned as an array, with the same order as the binds
5927-
in the statement. If `bindParams` was passed as an object, then
5928-
`outBinds` is returned as an object.
59295925

5930-
Here is an example program showing the use of binds:
5926+
Given the creation of the PL/SQL procedure `TESTPROC`:
5927+
5928+
```sql
5929+
CREATE OR REPLACE PROCEDURE testproc (
5930+
p_in IN VARCHAR2, p_inout IN OUT VARCHAR2, p_out OUT NUMBER)
5931+
AS
5932+
BEGIN
5933+
p_inout := p_in || p_inout;
5934+
p_out := 101;
5935+
END;
5936+
/
5937+
show errors
5938+
```
5939+
5940+
The procedure `TESTPROC` can be called with:
59315941

59325942
```javascript
59335943
var oracledb = require('oracledb');
59345944
. . .
59355945
var bindVars = {
59365946
i: 'Chris', // default direction is BIND_IN. Data type is inferred from the data
59375947
io: { val: 'Jones', dir: oracledb.BIND_INOUT },
5938-
o: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
5948+
o: { dir: oracledb.BIND_OUT, type: oracledb.NUMBER },
59395949
}
59405950
connection.execute(
59415951
"BEGIN testproc(:i, :io, :o); END;",
@@ -5946,27 +5956,21 @@ connection.execute(
59465956
});
59475957
```
59485958
5949-
Given the creation of `TESTPROC` using:
5959+
Since `bindParams` is passed as an object, the `outBinds` property is
5960+
also an object. The Node.js output is:
59505961
5951-
```sql
5952-
CREATE OR REPLACE PROCEDURE testproc (
5953-
p_in IN VARCHAR2, p_inout IN OUT VARCHAR2, p_out OUT NUMBER)
5954-
AS
5955-
BEGIN
5956-
p_inout := p_in || p_inout;
5957-
p_out := 101;
5958-
END;
5959-
/
5960-
show errors
5962+
```
5963+
{ io: 'ChrisJones', o: 101 }
59615964
```
59625965
5963-
The Node.js output would be:
5966+
PL/SQL allows named parameters in procedure and function calls. This
5967+
can be used in `execute()` like:
59645968
59655969
```
5966-
{ io: 'ChrisJones', o: 101 }
5970+
"BEGIN testproc(p_in => :i, p_inout => :io, p_out => :o); END;",
59675971
```
59685972
5969-
An alternative to the 'bind by name' syntax is 'bind by array' syntax:
5973+
An alternative to node-oracledb's 'bind by name' syntax is 'bind by array' syntax:
59705974
59715975
```javascript
59725976
var bindVars = [
@@ -5976,6 +5980,14 @@ var bindVars = [
59765980
];
59775981
```
59785982
5983+
When [`bindParams`](#executebindParams) is passed as an array, then
5984+
`outBinds` is returned as an array, with the same order as the OUT
5985+
binds in the statement:
5986+
5987+
```
5988+
[ 'ChrisJones', 101 ]
5989+
```
5990+
59795991
Mixing positional and named syntax is not supported. The following
59805992
will throw an error:
59815993

examples/plsqlfunc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ oracledb.getConnection(
5050
};
5151
connection.execute(
5252
"BEGIN :ret := testfunc(:p1, :p2); END;",
53+
// The equivalent call with PL/SQL named parameter syntax is:
54+
// "BEGIN :ret := testfunc(p1_in => :p1, p2_in => :p2); END;",
5355
bindvars,
5456
function (err, result) {
5557
if (err) {

examples/plsqlproc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ oracledb.getConnection(
5151
};
5252
connection.execute(
5353
"BEGIN testproc(:i, :io, :o); END;",
54+
// The equivalent call with PL/SQL named parameter syntax is:
55+
// "BEGIN testproc(p_in => :i, p_inout => :io, p_out => :o); END;",
5456
bindvars,
5557
function (err, result) {
5658
if (err) {

0 commit comments

Comments
 (0)