Tuesday, 9 May 2017

Include single quotes in concatenated string - Javascript

I am trying to generate the comparison operands for an Oracle query using Javascript, but the query keeps showing the escape character everywhere I have a single quote. Any suggestions on how I can get around this would be much appreciated.

let compOperands = "to_date('" + (moment(timeStamp).format("D-MMM-YYYY HH:mm:ss") + "', 'dd-mon-yyyy hh24:mi:ss')");

Console:

SELECT * FROM IVR_LZ_CALL_LEG WHERE START_TS > to_date(\'9-May-2017 06:32:32\', \'dd-mon-yyyy hh24:mi:ss\')

Note: I have also tried this and got the same result as above:

let compOperands = "to_date(\'" + (moment(timeStamp).format("D-MMM-YYYY HH:mm:ss") + "\', \'dd-mon-yyyy hh24:mi:ss\')");



via YeeP

No comments:

Post a Comment