doushifen4060 2010-09-23 16:26
浏览 48
已采纳

Oracle / PHP语法,用于获取并稍后在日期字段中存储时间戳值

There is a composite primary key stored in a DB that consists of a date field and a foreign key ID. Normally this would create duplicates however the date field (although it only displays the day, month, year appears to have timestamp information stored as well)

My question is how to extract the timestamp information (I think using the to_char field) and more importantly, how I can later insert a record and store the date and timestamp.

Right now I can store a date but not sure the syntax I would need to use to add the time to the Date field insert so it can be consistent with the values I pull from a table select.

  • 写回答

2条回答 默认 最新

  • dth2331 2010-09-23 16:35
    关注

    The Oracle DATE data type includes the time portion.

    To get the date from a DATE column using TO_CHAR:

    TO_CHAR(date_column, 'DD-MM-YYYY')
    

    ...not sure the syntax I would need to use to add the time to the Date field insert so it can be consistent with the values I pull from a table select.

    To specify the time portion to an existing date, use a combination of TO_DATE and TO_CHAR:

    TO_DATE(TO_CHAR(date_column, 'DD-MM-YYYY') || ' 23:59:00', 'DD-MON-YYYY HH24:MI:SS')
    

    ...changing 23:59:00 to whatever time you actually want. The double pipe (||) is what Oracle uses for string concatenation (it's also now ANSI standard).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 图书信息管理系统程序编写
  • ¥15 7-1 jmu-java-m02-使用二维数组存储多元线性方程组
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题