简体   繁体   English

将nodejs中的日期格式转换插入Oracle时间戳

[英]convert and Insert date format in nodejs into Oracle timestamp

 let date = moment(new Date()).format("YYYY-MM-DD hh:mm:ss.000000000 A");

// when i tried to insert date in table it is null // 当我试图在表格中插入日期时,它是 null

// TImestamp format in OracleDB is 14-03-22 3:53:08.901008000 PM // OracleDB 中的时间戳格式为 14-03-22 3:53:08.901008000 PM

INSERT INTO STUDENT VALUES(join_date) ( '14-03-22 3:53:08.901008000 PM')插入学生价值观(join_date)('14-03-22 3:53:08.901008000 PM')

How can get date format like YYYY-MM-DD HH:MM:SS.FF3 AM/PM because in oracle it supports this kind of timestamp如何获得像YYYY-MM-DD HH:MM:SS.FF3 AM/PM这样的日期格式,因为在 oracle 中它支持这种时间戳

In Oracle, a TIMESTAMP is a binary data type that consists of 7 - 13 bytes (century, year-of-century, month, day, hour, minute, second and between zero and six bytes for fractional seconds).在 Oracle 中, TIMESTAMP是一种二进制数据类型,由 7 - 13 个字节(世纪、世纪年、月、日、小时、分钟、秒和零到六个字节之间的小数秒)组成。 It ALWAYS contains those components and it is NEVER stored in a particular format.始终包含这些组件,并且从不以特定格式存储。

The client application you are using (ie SQL/Plus, SQL Developer, NodeJS, Java, etc.) may chose to DISPLAY the binary value with a default format but this is a function of the client application and NOT a function of the database.您正在使用的客户端应用程序(即 SQL/Plus、SQL Developer、NodeJS、Java 等)可能会选择以默认格式显示二进制值,但这是客户端应用程序的 function 而不是数据库的 function。 (Some client applications may use the NLS_TIMESTAMP_FORMAT session parameter from the database as their default format model but the implicit conversion from binary-to-string for display purposes is still something that the client application does, not the database, and not all clients use the database session variables for their defaults.) (一些客户端应用程序可能使用数据库中的NLS_TIMESTAMP_FORMAT session 参数作为它们的默认格式 model 但出于显示目的从二进制到字符串的隐式转换仍然是客户端应用程序而不是数据库所做的事情,并且并非所有客户端都使用数据库 session 个变量作为默认值。)

You should either:你应该:

  1. Use a timestamp literal:使用时间戳文字:

     INSERT INTO STUDENT (join_date) VALUES (TIMESTAMP '2022-03-14 15:53:08.901008000');
  2. Explicitly convert your formatted string to a timestamp binary data type using the TO_TIMESTAMP function with a format model:使用格式为 model 的TO_TIMESTAMP function 将格式化字符串显式转换为时间戳二进制数据类型:

     INSERT INTO STUDENT (join_date) VALUES ( TO_TIMESTAMP('14-03-22 3:53:08.901008000 PM', 'DD-MM-RR HH12:MI:SS.FF9 AM') )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM