[英]Insert Timestamp into Varchar2 column in Oracle Database
I am working with an application that interfaces with an Oracle 11g database. 我正在使用与Oracle 11g数据库连接的应用程序。 I need to insert a timestamp in the YYYYMMDDhhmmss format, into a Varchar2 column. 我需要将YYYYMMDDhhmmss格式的时间戳记插入Varchar2列。
My SQL update query is: 我的SQL更新查询是:
update CODELIST_XREF_ITEM set RECEIVER_ITEM= TIMESTAMP where LIST_NAME='BUSINESS_PROCESS'; 更新CODELIST_XREF_ITEM设置RECEIVER_ITEM = TIMESTAMP ,其中LIST_NAME ='BUSINESS_PROCESS';
The TIMESTAMP variable is where it need to be inserted. TIMESTAMP变量是需要在其中插入的位置。 I have tried setting the TIMESTAMP variable to CURRENT_TIMESTAMP , however I am not able to format that. 我尝试将TIMESTAMP变量设置为CURRENT_TIMESTAMP ,但是我无法对其进行格式化。
Any suggestions? 有什么建议么?
Thanks in advance for all your help! 预先感谢您的所有帮助!
If you want to insert the character representation of a timestamp (it actually appears that you want the character representation of an Oracle date
since you don't want fractional seconds or a time zone), you'd use the to_char
function. 如果要插入时间戳的字符表示(实际上,由于您不希望小数秒或时区,实际上您想要Oracle date
的字符表示),则可以使用to_char
函数。
to_char( sysdate, 'YYYYMMDDHH24MISS' )
So your UPDATE
statement would be 因此,您的UPDATE
语句将是
update CODELIST_XREF_ITEM
set RECEIVER_ITEM=to_char( sysdate, 'YYYYMMDDHH24MISS' )
where LIST_NAME='BUSINESS_PROCESS';
If you wanted to store fractional seconds or a time zone or do something else that required a timestamp
, you'd use the same to_char
function just with a different format mask. 如果要存储小数秒或时区,或执行其他需要timestamp
,则可以使用相同的to_char
函数,只是使用不同的格式掩码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.