How to convert an Oracle string to a TIMESTAMP type

Source: Internet
Author: User

When converting Oracle strings to TIMESTAMP or Date types in practical applications of computers, we need to use Oracle-related functions. In this process, we need to involve a lot of string applications, next let's take a look at the practical application of Oracle String Conversion!

Use Oracle functions:

TO_TIMESTAMP_TZ ('2017-3-9 17:51:23. 23-05:00 ', 'yyyy-MM-D HH24: MI: SS. ff tzh: tzm ')

TO_DATE (yourdate, 'yyyy-MM-D HH24: MI: ss ');

String to Date

T0_CHAR (yourdate, 'yyyy-MM-D HH24: MI: ss ');

Convert Date to string

Eg:

Update t_fl_flownote set sendtime = TO_TIMESTAMP_TZ ('2017-11-30 10:47:16 ', 'yyyy-MM-DD HH24: MI: ss ')

Transfer others' logs

We all know that date and timestamp are both expressions of date and time, but the two types of precision are different. The former is accurate to seconds, and the latter is precise to fractional_seconds_precision in decimal seconds ), it can be 0 to 9. The default value is 6.

Oracle String Conversion is simple for date type calculation, and many functions can be used for processing; the difference between the two timestamp is that it intuitively shows the number of days, hours, minutes, seconds, and decimal seconds,

SQL> create table test (T1 TIMESTAMP (6 ),

2 T2 TIMESTAMP (6 ));

The table has been created.

SQL> insert into test values (

2 to_timestamp ('2017-01-01 12:10:10. 1', 'yyyy-mm-dd hh24: mi: ss. ff '),

3 to_timestamp ('2017-01-01 12:20:10. 2', 'yyyy-mm-dd hh24: mi: ss. ff '));

One row has been created.

SQL>

SQL> insert into test values (

2 to_timestamp ('2017-01-01 12:10:10. 1', 'yyyy-mm-dd hh24: mi: ss. ff '),

3 to_timestamp ('2017-01-02 12:20:10. 2', 'yyyy-mm-dd hh24: mi: ss. ff '));

One row has been created.

SQL>

SQL> insert into test values (

2 to_timestamp ('2017-01-01 12:10:10. 1', 'yyyy-mm-dd hh24: mi: ss. ff '),

3 to_timestamp ('2017-01-02 13:40:20. 2', 'yyyy-mm-dd hh24: mi: ss. ff '));

One row has been created.

SQL> commit;

Submitted.

SQL>

The difference between the two timestamp is that it intuitively shows the number of days, hours, minutes, seconds, and decimal seconds:

SQL> select t2-t1 from test;

+ 000000000 00:10:00. 100000

+ 000000001 00:10:00. 100000

+ 000000001 01:30:10. 100000

SQL>

However, it is difficult to simply convert the data into a specific precision. It is not feasible to use a method similar to the date type. For example, to score:

SQL> select 1440 * (t2-t1) from test;

+ 000000010 00:02:24. 000000000

+ 000001450 00:02:24. 000000000

+ 000001530 04:02:24. 000000000

SQL>

The results are not originally expected, but multiplied by 1440 for each item of the original "how many days + how many hours + how many minutes + how many seconds + how many decimal seconds" and then processed in the traveling system. The above content is an introduction to Oracle String Conversion of the TIMESTAMP type or Date type. I hope you will get something.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.