Implicit conversion of data types in Oracle (implicit conversion)

Source: Internet
Author: User

Like other relational databases,OracleCan also perform some implicit data conversion, which writesSQLStatement hasVeryYou can manually convert many types of characters. Although we have introduced some methods for force conversion using functions such as to_char and to_date, implicit conversion is still good.

OracleIt can be implicitly converted between variable classes, for example, from String Conversion to numeric value.,Let's look at the example below.

SQL> select ename, Sal from EMP where sal = '000000 ′;

 

Ename Sal

-----------

The smith 1100

Adams 1100

 

The employee's salary was chosen here. We knew that the employee's salary was numeric, But we deliberately wrote it as a string. ResultOracleThe correct result is returned. This descriptionOracleImplicit direct conversion from string to numeric value.

Then compare the following example.

SQL> select last_day ('26-4Month-08') from dual;

 

Last_day ('

----

30-4Month-08

Here ourLast_dayThe function originally needs to provide a date type parameter, and we intentionally provide a string type parameter. HoweverOracleThe correct result is returned for us.OracleImplicit conversion from string to date is performed internally.

It should be noted that, if this example is not successfully executed on your machine, it is very likely that your default date format is different from this, if you do not know your date format, you can useSelect sysdate from dualThisSQLReturns the date format of your machine. GenerallyNls_langParameter Values

Both examples illustrateOracleSome implicit function conversions can be performed internally. Below isOracleIn general.

Slave

To

Varchar2 or char

Number

Varchar2 or char

Date

Number

Varchar2

Date

Varchar2

 

Note thatVarchar2,CharToDateIn the implicit conversion process, you must ensure that the format is the default time format of the local machine.

Except for implicit conversion,OracleIt also provides more flexible data type display conversion, which is more flexible.

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.