ocp1z0-047: Time Format

Source: Internet
Author: User
Tags commit numeric

This topic is the test time format, the date of the storage format, within the Oracle is composed of the following seven parts: Century, year, month, day, hour, minute, second.

OK, let's do a test:

Gyj@ocm> CREATE TABLE Gyj_order (order_id int,order_date date);

Table created.

gyj@ocm> INSERT into Gyj_order values (1,sysdate);

1 row created.

Gyj@ocm> commit;

Commit complete.

Gyj@ocm> SELECT * from Gyj_order where order_date> to_date (' June 2006 ', ' MON ddyyyy ');

Order_idorder_dat

---------- ---------

116-jul-13

Explain answer a is correct

Gyj@ocm> SELECT * from Gyj_order whereto_char (order_date, ' MON DD YYYY ') = ' June 16 2013 ';

Order_idorder_dat

---------- ---------

116-jul-13

Explain the answer b is correct

Gyj@ocm> Select To_char (add_months (sysdate,6), ' mondd YYYY ') from dual;

To_char (Add_mo

--------------

16 2014.

Gyj@ocm> SELECT * from Gyj_order whereorder_date> to_char (add_months (sysdate,6), ' MON DD YYYY ');

SELECT * from Gyj_order where Order_date>to_char (Add_months (sysdate,6), ' MON DD YYYY ')

*

ERROR at line 1:

Ora-01858:a non-numeric character is found where Anumeric was expected

EXPLANATION The answer c is incorrect, the time type and the character type cannot be compared

Gyj@ocm> SELECT * from Gyj_order where Order_datein (To_date (' 2013 ', ' MON dd YYYY '), To_char (' June 2013 ', ' MON DD YYYY '));

SELECT * from Gyj_order where Order_datein (To_date (' 2013 ', ' MON dd YYYY '), To_char (' June 2013 ', ' MON dd YYYY '))

*

ERROR at line 1:

Ora-01722:invalid number

Gyj@ocm> Select To_char (' 2013 ', ' MON ddyyyy ') from dual; Select To_char (' June 2013 ', ' MON DD YYYY ') from dual

*

ERROR at line 1:

Ora-01722:invalid number

The above writing is wrong, already is the character does not need to use the TO_CHAR transformation, looks the following writing is correct:

Gyj@ocm> Select To_char (to_date (' 2013 ', ' mondd YYYY '), ' MON DD YYYY ') from dual;

To_char (to_

-----------

April 16 2013

There are also time and character types can not be directly calculated, the following error:

Gyj@ocm> SELECT * from Gyj_order where Order_datein (To_char (To_date (' June 2013 ', ' MON dd YYYY '), ' MON dd YYYY '));

SELECT * from Gyj_order where Order_datein (To_char (To_date (' 2013 ', ' MON dd YYYY '), ' MON dd YYYY '))

*

ERROR at line 1:

Ora-01858:a non-numeric character is found where Anumeric was expected

Answer d is not correct

Final correct answer selected: AB

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/

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.