Skip to content

Commit 57612df

Browse files
committed
Show how to detect PL/SQL compilation warnings
1 parent 5e0ace4 commit 57612df

File tree

1 file changed

+63
-3
lines changed

1 file changed

+63
-3
lines changed

doc/api.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ For installation information, see the [Node-oracledb Installation Instructions][
475475
- 17.4 [Using DBMS_OUTPUT](#dbmsoutput)
476476
- 17.5 [Edition-Based Redefinition](#ebr)
477477
- 17.6 [Implicit Results](#implicitresults)
478+
- 17.7 [Creating PL/SQL Procedures and Functions](#plsqlcreate)
479+
- 17.7. [PL/SQL Compilation Warnings](#plsqlcompwarnings)
478480
18. [Working with CLOB, NCLOB and BLOB Data](#lobhandling)
479481
- 18.1 [Simple Insertion of LOBs](#basiclobinsert)
480482
- 18.2 [Simple LOB Queries and PL/SQL OUT Binds](#queryinglobs)
@@ -11416,9 +11418,6 @@ solutions:
1141611418
PL/SQL stored procedures, functions and anonymous blocks can be called
1141711419
from node-oracledb using [`execute()`](#execute).
1141811420

11419-
Note the error property of the callback is not set when PL/SQL
11420-
"success with info" warnings such as compilation warnings occur.
11421-
1142211421
### <a name="plsqlproc"></a> 17.1 PL/SQL Stored Procedures
1142311422

1142411423
The PL/SQL procedure:
@@ -11815,6 +11814,67 @@ Implicit Result Set 2
1181511814

1181611815
A runnable example is in [impres.js][138].
1181711816

11817+
### <a name="plsqlcreate"></a> 17.7 Creating PL/SQL Procedures and Functions
11818+
11819+
PL/SQL procedures and functions can easily be created in node-oracledb by
11820+
calling `connection.execute()`, for example:
11821+
11822+
```javascript
11823+
await connection.execute(
11824+
`CREATE OR REPLACE PROCEDURE no_proc
11825+
(p_in IN VARCHAR2, p_inout IN OUT VARCHAR2, p_out OUT NUMBER)
11826+
AS
11827+
BEGIN
11828+
p_inout := p_in || p_inout;
11829+
p_out := 101;
11830+
END;`
11831+
);
11832+
11833+
```
11834+
11835+
See the examples
11836+
[plsqlproc.js](https://github.com/oracle/node-oracledb/tree/master/examples/plsqlproc.js)
11837+
and
11838+
[plsqlfunc.js](https://github.com/oracle/node-oracledb/tree/master/examples/plsqlfunc.js).
11839+
11840+
#### <a name="plsqlcompwarnings"></a> 17.7.1 PL/SQL Compilation Warnings
11841+
11842+
When creating PL/SQL procedures and functions in node-oracledb, compilation
11843+
warnings must be manually checked for. This can be done by querying
11844+
`USER_ERRORS` like:
11845+
11846+
```javascript
11847+
await connection.execute(
11848+
`CREATE OR REPLACE PROCEDURE badproc AS
11849+
BEGIN
11850+
INVALID
11851+
END;`);
11852+
11853+
const r = await connection.execute(
11854+
`SELECT line, position, text
11855+
FROM user_errors
11856+
WHERE name = 'BADPROC' AND type = 'PROCEDURE'
11857+
ORDER BY name, type, line, position`,
11858+
[], { outFormat: oracledb.OUT_FORMAT_OBJECT }
11859+
);
11860+
11861+
if (r.rows.length) {
11862+
console.error(r.rows[0].TEXT);
11863+
console.error('at line', r.rows[0].LINE, 'position', r.rows[0].POSITION);
11864+
}
11865+
```
11866+
11867+
Output is like:
11868+
11869+
```
11870+
PLS-00103: Encountered the symbol "END" when expecting one of the following:
11871+
11872+
:= . ( @ % ;
11873+
The symbol ";" was substituted for "END" to continue.
11874+
11875+
at line 4 position 8
11876+
```
11877+
1181811878
## <a name="lobhandling"></a> 18. Working with CLOB, NCLOB and BLOB Data
1181911879

1182011880
Oracle Database uses LOB data types to store long objects. The CLOB type is used

0 commit comments

Comments
 (0)