Record of an NJS-016 exception for node oracledb
How it happened
Using node oracledb to develop a backend api and encountered NJS-016: buffer is too small for OUT binds exception for a simple select query: select a, b, c from tab@dblink

Debugging
- Googled
NJS-016: buffer is too small for OUT bindsand found little help. None of them suits my case. - Maybe it has something to do with database link ? Charset for local database is
AMERICAN_AMERICA.AL32UTF8and for remote database isAMERICAN_AMERICA.ZHS16GBK. Changed charset environment variable to the same as remote database, still no luck. - Found that column
bhas some weired behavior: for chinese character value神经阻滞it only shows first two characters神经when environment variable is set toAMERICAN_AMERICA.AL32UTF8, different from database charsetAMERICAN_AMERICA.ZHS16GBK. Columnbdefinition isvarchar2(8). Maybe has something to do with this ?
Reasoning
For charset AMERICAN_AMERICA.ZHS16GBK, each chinese character is 2 bytes wide.
For charset AMERICAN_AMERICA.AL32UTF8, each chinese character is 3 bytes wide.
With varchar2(8), it can hold 4 characters on AMERICAN_AMERICA.ZHS16GBK, 2 characters on AMERICAN_AMERICA.AL32UTF8. That’s why it only shows 2 characters when environment variable is AMERICAN_AMERICA.AL32UTF8.NJS-016 indicates out binds with varhcar2(8) cannot hold 神经阻滞 as it is 4×3=12 bytes wide.
Solution
- Expand column width from
varchar2(8)to a at leastvarchar2(12)(Intrusive, not recommended). - Avoid using database links when charset is different on remote database. Create a distinct connection pool for remote database and execute query on a connection fetched from the pool.
Record of an NJS-016 exception for node oracledb
https://blog-cdt1.vercel.app/2022/07/12/Record-of-an-NJS-016-exception-for-node-oracledb/

