Solved

How to Cast VARCHAR2 to TIMESTAMP(6) In Select Statement In Oracle?

Posted on 2014-11-23
1
455 Views
Last Modified: 2014-11-23
Dear Experts,

I have a table with a field varchar2(24) with values like: '2012-09-27 01:40:31.0' (I think trailing spaces exist as well)

I want to perform insert into table select that field but the corresponding field in the target table is type TIMESTAMP(6)

How can I achieve this?

BR
0
Comment
Question by:GurcanK
1 Comment
 
LVL 34

Accepted Solution

by:
johnsone earned 500 total points
Comment Utility
You just need to include a to_timestamp function on the character field.

insert into mytab (col1) select to_timestamp(col2, 'yyyy-mm-dd hh24:mi:ss.ff') from mytab;

If for any reason a value is not in that specific format, you will get an error.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now