Skip to content

Commit 2dd61b5

Browse files
committed
Add a LIKE bind example
1 parent 14a0813 commit 2dd61b5

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

doc/api.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ For installation information, see the [Node-oracledb Installation Instructions][
499499
- 21.4 [REF CURSOR Bind Parameters](#refcursors)
500500
- 21.5 [LOB Bind Parameters](#lobbinds)
501501
- 21.6 [Binding Multiple Values to a SQL `WHERE IN` Clause](#sqlwherein)
502-
- 21.7 [Binding Column and Table Names in Queries](#sqlbindtablename)
502+
- 21.7 [Binding in a `LIKE` or `REGEXP_LIKE` Clause](#sqlbindlike)
503+
- 21.8 [Binding Column and Table Names in Queries](#sqlbindtablename)
503504
22. [Oracle Database Objects and Collections](#objects)
504505
- 22.1 [Inserting Objects](#objectinsert)
505506
- 22.2 [Fetching Objects](#objectfetch)
@@ -13731,7 +13732,47 @@ for really large numbers of items, you might prefer to use a global
1373113732
temporary table. Some solutions are given in [On Cursors, SQL, and
1373213733
Analytics][59] and in [this StackOverflow answer][60].
1373313734

13734-
### <a name="sqlbindtablename"></a> 21.7 Binding Column and Table Names in Queries
13735+
### <a name="sqlbindlike"></a> 21.7 Binding in a `LIKE` or `REGEXP_LIKE` Clause
13736+
13737+
To do pattern matching with a `LIKE` clause, bind a string containing the
13738+
pattern match wildcards, for example:
13739+
13740+
```javascript
13741+
const pattern = "%uth%";
13742+
13743+
result = await connection.execute(
13744+
`SELECT CITY FROM LOCATIONS WHERE CITY LIKE :bv`,
13745+
{ bv: pattern }
13746+
);
13747+
console.log(result.rows[0]);
13748+
```
13749+
13750+
Output is like:
13751+
13752+
```
13753+
[ [ 'South Brunswick' ], [ 'South San Francisco' ], [ 'Southlake' ] ]
13754+
```
13755+
13756+
The same is true for regular expression functions such as `REGEXP_LIKE` and
13757+
`REGEXP_SUBSTR`. For example:
13758+
13759+
```javascript
13760+
const pattern = ',[^,]+,';
13761+
13762+
result = await connection.execute(
13763+
`SELECT REGEXP_SUBSTR('500 Oracle Parkway, Redwood Shores, CA', :bv) FROM DUAL`,
13764+
{ bv: pattern }
13765+
);
13766+
console.log(result.rows);
13767+
```
13768+
13769+
Output is like:
13770+
13771+
```
13772+
[ [ ', Redwood Shores,' ] ]
13773+
```
13774+
13775+
### <a name="sqlbindtablename"></a> 21.8 Binding Column and Table Names in Queries
1373513776

1373613777
It is not possible to bind table names in queries. Instead use a
1373713778
hard-coded Allow List of names to build the final SQL statement, for

0 commit comments

Comments
 (0)