gtsolov
gtsolov

Reputation: 152

Node.js - Oracle DB and fetchAsString format

I am stuck on a problem and I am not sure what is the best way to solve it. I have a date column that I want to select and I want to fetch it as a string. Which is great, node-oracledb module has this option with fetchAsString mehotd. But it fetches the date like this for example 10-JAN-16 and I want to fetch it like this 10-01-2016. Is there a way to do that from the node-oracledb module, or I should modify the date after I get the result from the query?

UPDATE: I mean solution without to_char in the query and without query modifications

Upvotes: 1

Views: 2412

Answers (1)

Dan McGhan
Dan McGhan

Reputation: 4659

Check out this section of my series on Working with Dates in JavaScript, JSON, and Oracle Database: https://dzone.com/articles/working-with-dates-using-the-nodejs-driver

The logon trigger shows an example of using alter session to set the default date format. Keep in mind that there is NLS_DATE_FORMAT, NLS_TIMESTAMP_FORMAT, NLS_TIMESTAMP_TZ_FORMAT.

I only show NLS_TIMESTAMP_TZ_FORMAT because I convert to that type in the examples that follow as I need to do some time zone conversion for the date format I'm using.

Another way to set the NLS parameters is to use environment variables of the same name. Note that this method will not work unless you set the NLS_LANG environment variable as well.

Upvotes: 1

Related Questions