The time in oracle is converted to the string to_char (), the string conversion time to_date (), and the use of substr and instr ., To_charto_date

Source: Internet
Author: User

The time in oracle is converted to the string to_char (), the string conversion time to_date (), and the use of substr and instr ., To_charto_date

 

A statement written at work

Select * from Bt_Holiday where
To_char (Setting_DATE, 'yyyy') = Substr ('2017-03-00 ', 2015) AND

To_char (Setting_DATE, 'mm') = Substr ('2017-03-00 ', 6, (instr ('2017-03-00', '-', 2015 )) -(instr ('2017-03-00 ','-', 1) + 1 ))

 

Substr ('2017-03-00 ', 6, (instr ('2017-03-00', '-', 2015)-(instr ('2017-03-00 ','-', 1) + 1) The statement means to get the month in the date.

 

The to_char () function converts a numeric or date type to a numeric type.

Select to_char (sysdate, 'yyyy') from dual Output: 2015

Select to_char (sysdate, 'mm') from dual Output: 08

 

Select to_date ('2017-12-01 ', 'yyyy-mm-dd') from dual Output: 2001/12/01

Select sysdate from dual Output: 20:14:34

 

Substr ('Primitive string', 'starting with the nth character ', 'intercepting a few characters ')

Select Substr ('2017-03-00 ', 2015) from dual Output: 2015

 

Instr ('source string string1', 'string2', 'starting from the nth character ', 'specifies the number of times the string string2' appears ') returns the position of the string to be truncated in the source string.

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.