Oracle's time-to-string To_char (), string-to-time to_date (), and the use of substr and instr.

Source: Internet
Author: User

A statement written in the work

SELECT * FROM Bt_holiday where
To_char (setting_date, ' YYYY ') =substr (' 2015-03-00 ', 1,4) and

To_char (setting_date, ' MM ') =substr (' 2015-03-00 ', 6, (InStr (' 2015-03-00 ', '-') ')-(InStr (' 2015-03-00 ', '-', 1) +1))

Substr (' 2015-03-00 ', 6, (InStr (' 2015-03-00 ', '-', ') ')-(InStr (' 2015-03-00 ', '-', ' 1 ') +1)) The statement means the month in the acquisition date.

The function of the To_char () function is to convert a numeric or date type into a character type.

Select To_char (sysdate, ' YYYY ') from dual output: 2015

Select To_char (sysdate, ' MM ') from dual output: 08

Select To_date (' 2001-12-01 ', ' YYYY-MM-DD ') from dual output: 2001/12/01

Select Sysdate from dual output is: 2015/8/17 20:14:34

Substr (' Primitive string ', ' start of character ', ' intercept a few characters ')

Select Substr (' 2015-03-00 ', 1,4) from dual output to: 2015

Instr (' Source string string1 ', ' string to find in string1 string2 ', ' start with the first few characters ', ' to find the first occurrence of string string2 ') returns the position of the string to intercept in the source string

Oracle's time-to-string To_char (), string-to-time to_date (), and the use of substr and instr.

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.